Make WordPress Core

Changeset 56043


Ignore:
Timestamp:
06/26/2023 08:55:04 PM (6 months ago)
Author:
audrasjb
Message:

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.

Location:
trunk
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r56030 r56043  
    35773577    }
    35783578
     3579    $previous_status = $post->post_status;
     3580
    35793581    /**
    35803582     * Filters whether a post trashing should take place.
    35813583     *
    35823584     * @since 4.9.0
    3583      *
    3584      * @param bool|null $trash Whether to go forward with trashing.
    3585      * @param WP_Post   $post  Post object.
     3585     * @since 6.3.0 Added the `$previous_status` parameter.
     3586     *
     3587     * @param bool|null $trash           Whether to go forward with trashing.
     3588     * @param WP_Post   $post            Post object.
     3589     * @param string    $previous_status The status of the post about to be trashed.
    35863590     */
    3587     $check = apply_filters( 'pre_trash_post', null, $post );
     3591    $check = apply_filters( 'pre_trash_post', null, $post, $previous_status );
    35883592
    35893593    if ( null !== $check ) {
     
    35953599     *
    35963600     * @since 3.3.0
    3597      *
    3598      * @param int $post_id Post ID.
     3601     * @since 6.3.0 Added the `$previous_status` parameter.
     3602     *
     3603     * @param int    $post_id         Post ID.
     3604     * @param string $previous_status The status of the post about to be trashed.
    35993605     */
    3600     do_action( 'wp_trash_post', $post_id );
    3601 
    3602     add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
     3606    do_action( 'wp_trash_post', $post_id, $previous_status );
     3607
     3608    add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status );
    36033609    add_post_meta( $post_id, '_wp_trash_meta_time', time() );
    36043610
     
    36203626     *
    36213627     * @since 2.9.0
    3622      *
    3623      * @param int $post_id Post ID.
     3628     * @since 6.3.0 Added the `$previous_status` parameter.
     3629     *
     3630     * @param int    $post_id         Post ID.
     3631     * @param string $previous_status The status of the post at the point where it was trashed.
    36243632     */
    3625     do_action( 'trashed_post', $post_id );
     3633    do_action( 'trashed_post', $post_id, $previous_status );
    36263634
    36273635    return $post;
     
    36573665     *
    36583666     * @since 4.9.0
    3659      * @since 5.6.0 The `$previous_status` parameter was added.
     3667     * @since 5.6.0 Added the `$previous_status` parameter.
    36603668     *
    36613669     * @param bool|null $untrash         Whether to go forward with untrashing.
     
    36723680     *
    36733681     * @since 2.9.0
    3674      * @since 5.6.0 The `$previous_status` parameter was added.
     3682     * @since 5.6.0 Added the `$previous_status` parameter.
    36753683     *
    36763684     * @param int    $post_id         Post ID.
     
    37183726     *
    37193727     * @since 2.9.0
    3720      * @since 5.6.0 The `$previous_status` parameter was added.
     3728     * @since 5.6.0 Added the `$previous_status` parameter.
    37213729     *
    37223730     * @param int    $post_id         Post ID.
Note: See TracChangeset for help on using the changeset viewer.