Opened 10 years ago
Last modified 5 weeks ago
#35871 new defect (bug)
before_delete_post incorrectly triggered from edit.php to post.php
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | needs-testing |
| Focuses: | administration | Cc: |
Description
It seems there's a bug where before_delete_post triggers when clicking the post name (on edit.php) to go to the post.php admin edit screen. I have this code
<?php add_action('before_delete_post', $plugin_admin, 'prevent_club_deletion', 5); public function prevent_club_deletion() { global $post_type; if ( $post_type != 'club' ) return; $redirect = ( isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : get_admin_url(1, 'edit.php?post_type=club') ); wp_redirect( $redirect ); exit(); }
It randomly triggers the redirect when attempting to head into single edit screen for a post. It's a hierarchical CPT and the bug occurs for both parent and child pages. Tested with custom theme (no hooks really) and no plugins activated (except the one that creates the CPT and this hook).
Change History (7)
#2
@
10 years ago
Hi @boonebgorges - Thank you :)
Me neither.. I was thinking of something like revisions or maybe the heartbeat api having a role in it.
So should I use the before_delete_post hook for it or maybe pre_delete_post since it runs even earlier?
#3
@
10 years ago
Yes, I was thinking something like:
add_action( 'before_delete_post', function() {
error_log( print_r( debug_backtrace(), true ) );
error_log( print_r( $_SERVER, true ) );
}, 0 );
#5
@
10 years ago
That was my suspicion as well. I'm guessing they run on wp-cron so it would make sense that they'd run when I click the post link (interact with the website).
Hi @Jonathandejong - Welcome to WordPress Trac!
I can't think of a reason why WP itself would be triggering a post deletion when clicking on a post name from edit.php.
Your best next step is to get a backtrace. I'd suggest writing a small plugin that records the contents of
$_SERVERas well asdebug_backtrace()into a log file wheneverwp_delete_post()is called. Then, use the site until you trigger the redirect behavior you've described.