Skip to content

Commit

Permalink
Customize: Pass the previous status to post trash hooks when trashing…
Browse files Browse the repository at this point in the history
… a changeset.

This ensures that the correct number of arguments is passed to post trash hooks in `WP_Customize_Manager::trash_changeset_post()`, which bypasses `wp_trash_post()`.

Follow-up to [56043].

Props joelcj91, mukesh27.
Fixes #60183.

git-svn-id: https://develop.svn.wordpress.org/trunk@57238 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jan 3, 2024
1 parent 67296ea commit 0e55989
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/wp-includes/class-wp-customize-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3079,25 +3079,26 @@ public function trash_changeset_post( $post ) {
return false;
}

$previous_status = $post->post_status;

/** This filter is documented in wp-includes/post.php */
$check = apply_filters( 'pre_trash_post', null, $post );
$check = apply_filters( 'pre_trash_post', null, $post, $previous_status );
if ( null !== $check ) {
return $check;
}

/** This action is documented in wp-includes/post.php */
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() );

$old_status = $post->post_status;
$new_status = 'trash';
$wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
clean_post_cache( $post->ID );

$post->post_status = $new_status;
wp_transition_post_status( $new_status, $old_status, $post );
wp_transition_post_status( $new_status, $previous_status, $post );

/** This action is documented in wp-includes/post.php */
do_action( "edit_post_{$post->post_type}", $post->ID, $post );
Expand All @@ -3119,7 +3120,7 @@ public function trash_changeset_post( $post ) {
wp_trash_post_comments( $post_id );

/** This action is documented in wp-includes/post.php */
do_action( 'trashed_post', $post_id );
do_action( 'trashed_post', $post_id, $previous_status );

return $post;
}
Expand Down

0 comments on commit 0e55989

Please sign in to comment.