Customize: Introduce `WP_Customize_Manager::trash_changeset_post()` to reduce duplication and ensure proper changeset trashing logic.
Trashing a changeset via `wp_trash_post()` does not have the desired result since it mutates `post_content` (via Kses) and the `post_name` (even though it is a UUID). Props dlh. See #39896, #42030. Fixes #42175. Built from https://develop.svn.wordpress.org/trunk@41824 git-svn-id: http://core.svn.wordpress.org/trunk@41658 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c6f2ff7a8e
commit
3f2b453a4d
|
@ -2830,6 +2830,79 @@ final class WP_Customize_Manager {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trash or delete a changeset post.
|
||||||
|
*
|
||||||
|
* The following re-formulates the logic from `wp_trash_post()` as done in
|
||||||
|
* `wp_publish_post()`. The reason for bypassing `wp_trash_post()` is that it
|
||||||
|
* will mutate the the `post_content` and the `post_name` when they should be
|
||||||
|
* untouched.
|
||||||
|
*
|
||||||
|
* @since 4.9.0
|
||||||
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
|
* @see wp_trash_post()
|
||||||
|
*
|
||||||
|
* @param int|WP_Post $post The changeset post.
|
||||||
|
* @return mixed A WP_Post object for the trashed post or an empty value on failure.
|
||||||
|
*/
|
||||||
|
public function trash_changeset_post( $post ) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$post = get_post( $post );
|
||||||
|
|
||||||
|
if ( ! ( $post instanceof WP_Post ) ) {
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
$post_id = $post->ID;
|
||||||
|
|
||||||
|
if ( ! EMPTY_TRASH_DAYS ) {
|
||||||
|
return wp_delete_post( $post_id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'trash' === get_post_status( $post ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This filter is documented in wp-includes/post.php */
|
||||||
|
$check = apply_filters( 'pre_trash_post', null, $post );
|
||||||
|
if ( null !== $check ) {
|
||||||
|
return $check;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This action is documented in wp-includes/post.php */
|
||||||
|
do_action( 'wp_trash_post', $post_id );
|
||||||
|
|
||||||
|
add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_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 );
|
||||||
|
|
||||||
|
/** This action is documented in wp-includes/post.php */
|
||||||
|
do_action( 'edit_post', $post->ID, $post );
|
||||||
|
|
||||||
|
/** This action is documented in wp-includes/post.php */
|
||||||
|
do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
|
||||||
|
|
||||||
|
/** This action is documented in wp-includes/post.php */
|
||||||
|
do_action( 'save_post', $post->ID, $post, true );
|
||||||
|
|
||||||
|
/** This action is documented in wp-includes/post.php */
|
||||||
|
do_action( 'wp_insert_post', $post->ID, $post, true );
|
||||||
|
|
||||||
|
wp_trash_post_comments( $post_id );
|
||||||
|
|
||||||
|
/** This action is documented in wp-includes/post.php */
|
||||||
|
do_action( 'trashed_post', $post_id );
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle request to trash a changeset.
|
* Handle request to trash a changeset.
|
||||||
*
|
*
|
||||||
|
@ -2876,7 +2949,7 @@ final class WP_Customize_Manager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = wp_trash_post( $changeset_post_id );
|
$r = $this->trash_changeset_post( $changeset_post_id );
|
||||||
if ( ! ( $r instanceof WP_Post ) ) {
|
if ( ! ( $r instanceof WP_Post ) ) {
|
||||||
wp_send_json_error( array(
|
wp_send_json_error( array(
|
||||||
'code' => 'changeset_trash_failure',
|
'code' => 'changeset_trash_failure',
|
||||||
|
|
|
@ -2909,47 +2909,7 @@ function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_p
|
||||||
* and thus garbage collected.
|
* and thus garbage collected.
|
||||||
*/
|
*/
|
||||||
if ( ! wp_revisions_enabled( $changeset_post ) ) {
|
if ( ! wp_revisions_enabled( $changeset_post ) ) {
|
||||||
$post = $changeset_post;
|
$wp_customize->trash_changeset_post( $changeset_post->ID );
|
||||||
$post_id = $changeset_post->ID;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The following re-formulates the logic from wp_trash_post() as done in
|
|
||||||
* wp_publish_post(). The reason for bypassing wp_trash_post() is that it
|
|
||||||
* will mutate the post_content and the post_name when they should be
|
|
||||||
* untouched.
|
|
||||||
*/
|
|
||||||
if ( ! EMPTY_TRASH_DAYS ) {
|
|
||||||
wp_delete_post( $post_id, true );
|
|
||||||
} else {
|
|
||||||
/** This action is documented in wp-includes/post.php */
|
|
||||||
do_action( 'wp_trash_post', $post_id );
|
|
||||||
|
|
||||||
add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_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 );
|
|
||||||
|
|
||||||
/** This action is documented in wp-includes/post.php */
|
|
||||||
do_action( 'edit_post', $post->ID, $post );
|
|
||||||
|
|
||||||
/** This action is documented in wp-includes/post.php */
|
|
||||||
do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
|
|
||||||
|
|
||||||
/** This action is documented in wp-includes/post.php */
|
|
||||||
do_action( 'save_post', $post->ID, $post, true );
|
|
||||||
|
|
||||||
/** This action is documented in wp-includes/post.php */
|
|
||||||
do_action( 'wp_insert_post', $post->ID, $post, true );
|
|
||||||
|
|
||||||
/** This action is documented in wp-includes/post.php */
|
|
||||||
do_action( 'trashed_post', $post_id );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9-beta1-41823';
|
$wp_version = '4.9-beta1-41824';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue