Opened 9 years ago
Last modified 5 years ago
#35871 new defect (bug)
before_delete_post incorrectly triggered from edit.php to post.php
Reported by: | Jonathandejong | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.4.2 |
Component: | Posts, Post Types | Keywords: | reporter-feedback |
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 (5)
#2
@
9 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?
Note: See
TracTickets for help on using
tickets.
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
$_SERVER
as 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.