Filter hook 'wp_untrash_post_status'

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

View Source

wp_untrash_post_status

Filter Hook
Description
Filters the status that a post gets assigned when it is restored from the trash (untrashed). By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status` in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()` function is available for this. Prior to WordPress 5.6.0, restored posts were always assigned their original status.

Hook Information

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

Hook Parameters

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

Usage Examples

Basic Usage
<?php
// Hook into wp_untrash_post_status
add_filter('wp_untrash_post_status', 'my_custom_filter', 10, 3);

function my_custom_filter($new_status, $post_id, $previous_status) {
    // Your custom filtering logic here
    return $new_status;
}

Source Code Context

wp-includes/post.php:4076 - How this hook is used in WordPress core
<?php
4071  	 *
4072  	 * @param string $new_status      The new status of the post being restored.
4073  	 * @param int    $post_id         The ID of the post being restored.
4074  	 * @param string $previous_status The status of the post at the point where it was trashed.
4075  	 */
4076  	$post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status );
4077  
4078  	delete_post_meta( $post_id, '_wp_trash_meta_status' );
4079  	delete_post_meta( $post_id, '_wp_trash_meta_time' );
4080  
4081  	$post_updated = wp_update_post(

PHP Documentation

<?php
/**
	 * Filters the status that a post gets assigned when it is restored from the trash (untrashed).
	 *
	 * By default posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status`
	 * in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()`
	 * function is available for this.
	 *
	 * Prior to WordPress 5.6.0, restored posts were always assigned their original status.
	 *
	 * @since 5.6.0
	 *
	 * @param string $new_status      The new status of the post being restored.
	 * @param int    $post_id         The ID of the post being restored.
	 * @param string $previous_status The status of the post at the point where it was trashed.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.