The wp_trash_post
hook might be what you’re looking for:
Fires before a post is sent to the trash.
Also, there’s the trashed_post
hook:
Fires after a post is sent to the trash.
Here’s some untested code to get you started:
function my_wp_trash_post( $post_id ) {
$post_type = get_post_type( $post_id );
$post_status = get_post_status( $post_id );
if ( $post_type == 'mycpt' && in_array(
$post_status, array( 'publish','draft','future' )
)) {
// do your stuff
}
}
add_action( 'wp_trash_post', 'my_wp_trash_post' );
Related Posts:
- Where can I find a list of WordPress hooks?
- Is there a save_post hook for custom post types?
- Where is the right place to register/enqueue scripts & styles
- Difference between do_action and add_action
- Whats worth using add_action when we can simply use add_filter?
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Which hook if user profile information is updated?
- Are hooks called synchronously?
- Hook for URL Request
- Disable block from editor based on post type
- Difference between hooks Plugin_loaded and admin_int?
- Make W3 Total Cache “Empty All Caches” function purge varnish [closed]
- How to inject content after
- How to debug removal of rewrite rule flushing?
- function ‘wp_enable_block_templates’ not found
- How can I add a default description to uploaded files?
- Hook Widget to Woo Theme in functions.php
- Security around save_post hook
- How to pass arguments to add_action() [duplicate]
- How to use the post_updated hook before and after arguments
- Returning ACF custom field from publish_post
- How to modify an add_action() inside a loop of core function
- Hooks for Links Box [duplicate]
- I don’t understand why I shoud use lostpassword_url hook?
- Hook after wp_enqueue_scripts
- How to get session token of current user in wp_login hook?
- Hook any php file into the wordpress api
- Proper indentation of code generated inside hooks
- WP CLI Get all Enqueued Scripts and Styles
- Delay an action until current action is completed
- How to properly setup an activation hook
- How to remove scripts/style added to customize_controls_enqueue_scripts hook by current active theme
- Help to change the text for new website notification (wpmu_welcome_notification)
- Add parameter (time) to oembed
- How to remove query string from current page URL?
- Event-Driven Pattern vs MVC?
- Using hooks with extra parameters
- How to catch and modify custom field values when a page is updated
- Genesis: How to add content after aside and before the content-sidebar wrap
- Plugins rewrite rules the right way
- Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
- Plugin init hook
- Best action hook for placing ical requests
- `rest_user_query` can’t access post author in post edit screen
- Post Meta Emtpy on Publish Using Transition
- Add nofollow to custom widget posts
- Change Password Confirmed Email Text
- How to check post type when using sanitize_title hook?
- Duplicate Cron Jobs Using wp_next_scheduled / wp_schedule_event
- Register form: add custom field BEFORE default fields
- Custom Front End Registration – How Does the Key work in the Password Set Request?
- How to change the default mail when admin approuved an user?
- Lock user information once fields have been filled in
- read more, even if excerpt not trimmed
- How to distinguish on hook profile_update user registering, user resetting password or user updating profile?
- save_post hook to add terms getting deleted when using bulk edit
- Embeding style into the header via the function.php
- Add Different Actions To Different Page’s wp_footer
- Change the Default Plugin page filter to Active intead of All
- How to execute a hook asynchronously?
- Getting the post ID in parse_query
- Issues with if, else, and elseif statements
- Remove genesis_404 hook from genesis_loop [closed]
- What hooks do I need to hook into to capture ever wp_user creation/change?
- Is there a before_save_post hook or something similar
- Neccessary to call add_submenu_page and add_menu_page from admin_menu hook?
- “Seen by” Feature in posts [closed]
- Adding custom Bulk Actions
- How can I modify the header of RSS feed items?
- Print results of a WP_Query to wp-admin/upload.php within ‘delete_attachment’ hook?
- remove_action(‘save_post’) in function that was triggered by save post not working
- How to get template name or category before publish
- WordPress How to reorder Page/Post Settings
- How to call do_action() to pass arguments to hooked functions that take different number of args?
- WP hook to add custom content after the_title()
- Is it likely that do_action will have unexpected results?
- How to export category name and category link in wordpress json
- Error later wordpress 5.3.2 update. Please help
- How to abort a save operation with a WordPress hook?
- wp_get_current_user Not working
- is_page not triggering
- admin_post_(action) hook create console log error
- Check if front page within function passed to action
- Hook after creating a post and retrieve infos from this post immediatly
- $new_pass always returns null – password_reset hook
- How to resolve 500 error in post listing page?
- Object oriented programming, add_action in constructor not firing
- Get new (not old) post inside transition_post_status hook
- How to Show Different Information to your authors/contributers
- Cannot override hooks.php
- Removing action from template class
- Remove “enqueued” script from array
- Function is Missing an Action Hook
- How to access variables in the function where apply_filters() is called?
- PHP Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered
- change position of element using hook [closed]
- The acction hook stop working if i move it from plugin file to theme’s functions.php file
- wp_footer content appearing in admin area
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- Use wordpress search hooks to search a second database