Action hook 'wp_trash_post'

in WP Core File wp-includes/class-wp-customize-manager.php at line 3096

View Source

wp_trash_post

Action Hook
Description
Trashes or deletes a changeset post. The following re-formulates the logic from `wp_trash_post()` as done in `wp_publish_post()`. The reason for bypassing `wp_trash_post()` is that it will mutate the the `post_content` and the `post_name` when they should be untouched.

Hook Information

File Location wp-includes/class-wp-customize-manager.php View on GitHub
Hook Type Action
Line Number 3096

Hook Parameters

Type Name Description
int|WP_Post $post The changeset post.

Usage Examples

Basic Usage
<?php
// Hook into wp_trash_post
add_action('wp_trash_post', 'my_custom_function', 10, 1);

function my_custom_function($post) {
    // Your custom code here
}

Source Code Context

wp-includes/class-wp-customize-manager.php:3096 - How this hook is used in WordPress core
<?php
3091  		if ( null !== $check ) {
3092  			return $check;
3093  		}
3094  
3095  		/** This action is documented in wp-includes/post.php */
3096  		do_action( 'wp_trash_post', $post_id, $previous_status );
3097  
3098  		add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status );
3099  		add_post_meta( $post_id, '_wp_trash_meta_time', time() );
3100  
3101  		$new_status = 'trash';

PHP Documentation

<?php
/**
	 * Trashes or deletes a changeset post.
	 *
	 * The following re-formulates the logic from `wp_trash_post()` as done in
	 * `wp_publish_post()`. The reason for bypassing `wp_trash_post()` is that it
	 * will mutate the the `post_content` and the `post_name` when they should be
	 * untouched.
	 *
	 * @since 4.9.0
	 *
	 * @see wp_trash_post()
	 * @global wpdb $wpdb WordPress database abstraction object.
	 *
	 * @param int|WP_Post $post The changeset post.
	 * @return mixed A WP_Post object for the trashed post or an empty value on failure.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 1
  • File: wp-includes/class-wp-customize-manager.php
Related Hooks

Related hooks will be displayed here in future updates.