WordPress.org

Ready to get started?Download WordPress

Forums

Odd 2.3.2 Delete Post behavior (3 posts)

  1. kerosx
    Member
    Posted 6 years ago #

    Problem:

    When deleting a page from /wp-admin/edit-pages.php by clicking Delete under the Action column in the interface the page deletes but any function hooked into 'delete_post' doesn't _seem_ to be executed from my plugin. This all worked fine in WordPress 2.3.1 as I was developing it; the expected functionality executed as expected: WordPress deletes the Page and my plugin's class member functions are called and they clean up some external DB table records associated with the Page.

    Although I'm having this issue deleting from /wp-admin/edit-pages.php when clicking 'Delete' everything works as expected when the page is deleted using these methods (one being a hack):

    Opening the page in the page editor
    wp-admin/page.php?action=edit&post=[post number]

    and clicking the 'Delete this page'.

    --or--

    from /wp-admin/edit-pages.php in the admin interface copy the URL from the Delete link under the Action column, paste it in the web browser's address box, and execute it from there. The post deletes as expected and the records associated with my plugin are deleted too (the desired action). yet when you click the Delete link only the record disappears and my hooked functions never get called (it would seem; I've thrown some wp_die()'s in the called functions and WP doesn't skip a beat so I assume execution doesn't even reach them..."

    Problem is browser independent...Tested clicking the Delete link under FF and Safari and same problem...

    Tested under two installs of WordPress 2.3.2 -- same issue. tested under PHP 4.3.10 on a Linux box and PHP 5.2.4 under Mac OS X 10.5.

    I wrote a very simple plugin to test if the hook is being called when the 'Delete' link is clicked - the test proved positive, it calls the hooked delete_post successfully. So I am even more confused...

    add_action('delete_post', 'delete_post_test');

    function delete_post_test($post_id)
    {
    wp_die("-- $post_id --");
    }

    I am at a loss....I don't want to force users to delete a page using one of the alternate methods because it should work from /wp-admin/edit-pages.php like it had in older versions of WP. Could this be AJAX related?

    I don't understand how it can not work from this one part of the admin panel but delete fine from the Edit Page admin page...

    Any ideas?

  2. kerosx
    Member
    Posted 6 years ago #

    Update:

    I open template.php in 'wp-admin/includes' and goto line 195:

    <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) . "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>

    and remove

    onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\"

    from the line everything works as expected...

    Is there something not being sent to WP via this javascript function?

  3. fitztrev
    Member
    Posted 6 years ago #

    I just ran into the same problem as described above. The delete_post hook works fine if deleting from the edit post page, but not the Manage page, where deletes are handled via AJAX.

    The given solution does not work in 2.5-bleeding. I've spent over an hour trying to resolve it but no luck.

Topic Closed

This topic has been closed to new replies.

About this Topic