I need to have control over the trash / delete action on a custom post type.

I need to check for some conditions and decide if i should trash the CPT or not.

The wp_trash_action hook that is fired before the trash function does not give me the option to cancel the trash procedure.

To be more specific , i need to check for a condition when the user presses TRASH. If that condition is false then i need to stop the trashing action. If it is true it should continue.

  • does not give me this option, what option? Your question is very generic. Please file an edit and explain what you exactly need to do in order to get a specific to-the-point answer. Feb 18, 2016 at 5:50
  • @PieterGoosen just did.
    – e4rthdog
    Feb 18, 2016 at 5:52
  • Use plugin link Feb 18, 2016 at 6:02

1 Answer 1


Hook onto trashed_post and use wp_untrash_post() to reverse upon meeting a condition, pseudocode example...

add_action('trashed_post', 'wpse_218031_trashed_post');

function wpse_218031_trashed_post($post_id){
   //use post_id to check conditions... if not met call:
   if ( $some_condition ) {

trashed_post runs after wp_trash_post and after the post is moved to trash.

By the way, if the constant EMPTY_TRASH_DAYS is defined and is false posts will be permanently deleted and the subsequent hooks mentioned will not be fired, in which case wp_delete_post() will be called instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.