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 ) {
wp_untrash_post($post_id);
}
}
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.
Related Posts:
- wp_delete_post() deletes post instead of moving it to trash
- trash_post action with Custom Post Type
- Why trash folder got empty automatically?
- wp_trash_post not firing
- Sort trash by date post was trashed
- Trash in WP 3.8?
- Restore page after deleting it from trash
- How to change ‘Move to Trash’ to ‘Move to Draft’ for my blog’s users?
- is possible to interupt a post deletion when empty the trash
- Set “move to trash” as the default bulk action
- Problem deleting posts from trash
- How to prevent users from permanently deleting a post from trash, but allow them to restore it?
- How do I programatically empty trash?
- Turn Off Automatic Trash Deletion?
- Remove Trash / Delete option for Custom Post Type / Taxonomy
- Does WP fire delete_post when trashed posts are automatically deleted?
- How to add/retrieve the post trash link?
- Trash bin for categories
- Comments screen in backend, how to disable Quick Edit | Edit | History | Spam | for non admins
- How can I hook into existing WordPress Bulk actions?
- How to hook in to bulk trash posts
- WordPress has a trash for users? (Wrong result for count_user, greater than expected)
- Restrict access to the Trash folder in Posts
- How to change redirect after moving a page to trash?
- Error after deleting Custom Post Type with a function (no trash used)
- Undelete post (untrash)?
- Is there an action that is called when a post is restored from the trash?
- get_post() function returns post even if it is trashed
- Exclude trash from save_post
- Add frontend “Restore” link
- Dynamically create/remove terms in taxonomy when custom post type is published/trashed
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- How to add a column to the Trash page?
- Custom Role can’t trash Custom Post Type
- Can a user with admin role get ‘Sorry, you are not allowed to move this item to the Trash’ error when trashing a post?
- Restore trashed posts with comments
- custom post type, hide or disable the trash button in publish meta box
- Deleted pages showing up when querying for child pages
- How to restore permanently trash page? [closed]
- How to untrash a post only if it was not a draft?
- When trashing a post, also trash related comments
- Comment Spammed vs Trashed
- Deleting the attached “comment replies” when trashing a comment
- Shortcode to delete post from front end
- How to use update_post_meta inside wp_trash_post
- How can Reusable Blocks be fully deleted?
- posts comments goes to trash
- How to cancel the trash action inside wp_trash_post
- Missing ‘Move to Trash’ option from bulk select box
- How to retrieve the date on which a post was moved to trash?
- How to recover permanently deleted blog posts?
- Get rid of “trash can” for custom post type
- Remove Featured Image & All Media Uploaded to the Post
- SQL Command for restoring trashed comments
- How to cancel an action hooked to untrash_post? or any hook
- Restrict access to trash, only admin
- How to restore all items from trash
- How can I specify the post status of an untrashed post?
- Cancelled orders move to Trash automatically in Woocommerce – how to disable?
- Script doesn’t trash custom post types. Instead it duplicates the post and generate new versions in the trash
- wp_trash_post hook – problem with page updating if using wp_die
- Nonce for Trashing Item
- Post deleted in trash [closed]
- What’s the difference with trash_comment and wp_trash_comment?
- Conditional tag-like function to tell if post is in trash?
- Prevent users to delete comments from trash
- How to display “Trash” in my custom post type?
- Bulk trashing post ‘fails’
- WordPress deletes custom posts instead of trash them
- How can i take all ids from untrash_post action?
- Changing a post status name
- wp.getPosts with status = ‘trash’ using node.js
- Run Jquery Script after delete post in front end
- wp_trash_post retrashes already trashed comments?
- transition_comment_status gets called when untrashing comments
- Trash a post, send associated comments into the trash bin (change status)
- Conditionally process comments while ignoring replies
- get_option(‘sticky_posts’) returns stickies that are in trash
- WP Posts Not Adding Up
- Create action running on trashed_post hook to modify post_meta value
- wp_trash_post not firing as expected (also applies to trashed_post)