From d61ec19da0f420fdd2431c0e2abcd679b9bfc96d Mon Sep 17 00:00:00 2001 From: audrasjb Date: Mon, 26 Jun 2023 20:57:22 +0000 Subject: [PATCH] Posts, Post Types: Add a `$previous_status` parameter to `wp_trash_post()` related hooks. This adds a `$previous_status` parameter to the `pre_trash_post`, `wp_trash_post`, and `trashed_post` hooks. Props mujuonly, mukesh27, nihar007, dhruvishah2203, SergeyBiryukov, costdev, hugod, audrasjb, oglekler. Fixes #58392. Built from https://develop.svn.wordpress.org/trunk@56043 git-svn-id: http://core.svn.wordpress.org/trunk@55555 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 30 +++++++++++++++++++----------- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index fcd948066d..abf94bcbe5 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3576,15 +3576,19 @@ function wp_trash_post( $post_id = 0 ) { return false; } + $previous_status = $post->post_status; + /** * Filters whether a post trashing should take place. * * @since 4.9.0 + * @since 6.3.0 Added the `$previous_status` parameter. * - * @param bool|null $trash Whether to go forward with trashing. - * @param WP_Post $post Post object. + * @param bool|null $trash Whether to go forward with trashing. + * @param WP_Post $post Post object. + * @param string $previous_status The status of the post about to be trashed. */ - $check = apply_filters( 'pre_trash_post', null, $post ); + $check = apply_filters( 'pre_trash_post', null, $post, $previous_status ); if ( null !== $check ) { return $check; @@ -3594,12 +3598,14 @@ function wp_trash_post( $post_id = 0 ) { * Fires before a post is sent to the Trash. * * @since 3.3.0 + * @since 6.3.0 Added the `$previous_status` parameter. * - * @param int $post_id Post ID. + * @param int $post_id Post ID. + * @param string $previous_status The status of the post about to be trashed. */ - do_action( 'wp_trash_post', $post_id ); + do_action( 'wp_trash_post', $post_id, $previous_status ); - add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status ); + add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status ); add_post_meta( $post_id, '_wp_trash_meta_time', time() ); $post_updated = wp_update_post( @@ -3619,10 +3625,12 @@ function wp_trash_post( $post_id = 0 ) { * Fires after a post is sent to the Trash. * * @since 2.9.0 + * @since 6.3.0 Added the `$previous_status` parameter. * - * @param int $post_id Post ID. + * @param int $post_id Post ID. + * @param string $previous_status The status of the post at the point where it was trashed. */ - do_action( 'trashed_post', $post_id ); + do_action( 'trashed_post', $post_id, $previous_status ); return $post; } @@ -3656,7 +3664,7 @@ function wp_untrash_post( $post_id = 0 ) { * Filters whether a post untrashing should take place. * * @since 4.9.0 - * @since 5.6.0 The `$previous_status` parameter was added. + * @since 5.6.0 Added the `$previous_status` parameter. * * @param bool|null $untrash Whether to go forward with untrashing. * @param WP_Post $post Post object. @@ -3671,7 +3679,7 @@ function wp_untrash_post( $post_id = 0 ) { * Fires before a post is restored from the Trash. * * @since 2.9.0 - * @since 5.6.0 The `$previous_status` parameter was added. + * @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. @@ -3717,7 +3725,7 @@ function wp_untrash_post( $post_id = 0 ) { * Fires after a post is restored from the Trash. * * @since 2.9.0 - * @since 5.6.0 The `$previous_status` parameter was added. + * @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. diff --git a/wp-includes/version.php b/wp-includes/version.php index 90248a29c8..8c1ae716a4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-56042'; +$wp_version = '6.3-alpha-56043'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.