How to cancel an action hooked to untrash_post? or any hook

its a little clumsy but you could combine what you are already doing with the ‘untrashed_post’ hook which fires after the post has been untrashed

here are the rough steps:

  • use ‘untrash_post’ hook to do your checking (like you are now)
  • if you need to cancel the untrash, store a flag in post meta with ie. update_post_meta( $post_id, ‘keep_trashed’, true );
  • use ‘untrashed_post’ to check if the post should be retrashed with get_post_meta( $post_id, ‘keep_trashed’, true );
  • if so, use wp_trash_post( $post_id ); to retrash the post
  • dump the post meta delete_post_meta( $post_id, ‘keep_trashed’ );