Action hook 'untrash_post'

in WP Core File wp-includes/post.php at line 4057

View Source

untrash_post

Action Hook
Description
Fires before a post is restored from the Trash.

Hook Information

File Location wp-includes/post.php View on GitHub
Hook Type Action
Line Number 4057

Hook Parameters

Type Name Description
int $post_id Post ID.
string $previous_status The status of the post at the point where it was trashed.

Usage Examples

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

function my_custom_function($post_id, $previous_status) {
    // Your custom code here
}

Source Code Context

wp-includes/post.php:4057 - How this hook is used in WordPress core
<?php
4052  	 * @since 5.6.0 Added the `$previous_status` parameter.
4053  	 *
4054  	 * @param int    $post_id         Post ID.
4055  	 * @param string $previous_status The status of the post at the point where it was trashed.
4056  	 */
4057  	do_action( 'untrash_post', $post_id, $previous_status );
4058  
4059  	$new_status = ( 'attachment' === $post->post_type ) ? 'inherit' : 'draft';
4060  
4061  	/**
4062  	 * Filters the status that a post gets assigned when it is restored from the trash (untrashed).

PHP Documentation

<?php
/**
	 * Fires before a post is restored from the Trash.
	 *
	 * @since 2.9.0
	 * @since 5.6.0 Added the `$previous_status` parameter.
	 *
	 * @param int    $post_id         Post ID.
	 * @param string $previous_status The status of the post at the point where it was trashed.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 2
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.