wp_untrash_post_status хук-фильтрWP 5.6.0

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() is available for this.

Prior to WordPress 5.6.0, restored posts were always assigned their original status.

Использование

add_filter( 'wp_untrash_post_status', 'wp_kama_untrash_post_status_filter', 10, 3 );

/**
 * Function for `wp_untrash_post_status` filter-hook.
 * 
 * @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.
 *
 * @return string
 */
function wp_kama_untrash_post_status_filter( $new_status, $post_id, $previous_status ){

	// filter...
	return $new_status;
}
$new_status(строка)
The new status of the post being restored.
$post_id(int)
The ID of the post being restored.
$previous_status(строка)
The status of the post at the point where it was trashed.

Список изменений

С версии 5.6.0 Введена.

Где вызывается хук

wp_untrash_post()
wp_untrash_post_status
wp-includes/post.php 3665
$post_status = apply_filters( 'wp_untrash_post_status', $new_status, $post_id, $previous_status );

Где используется хук в WordPress

wp-admin/edit.php 141
add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
wp-admin/edit.php 157
remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10 );