From 9cbcab94579dede00db4e0adb752664a52ad20f0 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 26 Sep 2017 20:32:46 +0000 Subject: [PATCH] Customize: Dismiss all autosaved auto-drafts for user and not just the one suggested when dismissing restoration notification. Amends [41597]. See #39896. git-svn-id: https://develop.svn.wordpress.org/trunk@41603 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 2 +- .../class-wp-customize-manager.php | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 17ce623f6c..5d361b8271 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -5510,7 +5510,7 @@ wp.ajax.post( 'dismiss_customize_changeset_autosave', { wp_customize: 'on', customize_theme: api.settings.theme.stylesheet, - customize_changeset_uuid: api.settings.changeset.latestAutoDraftUuid || api.settings.changeset.uuid, + customize_changeset_uuid: api.settings.changeset.uuid, nonce: api.settings.nonce.dismiss_autosave } ); } ); diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 33f423aacb..a37d431dc1 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -3054,15 +3054,26 @@ final class WP_Customize_Manager { } $changeset_post_id = $this->changeset_post_id(); - if ( empty( $changeset_post_id ) ) { - wp_send_json_error( 'missing_changeset', 404 ); - } - if ( 'auto-draft' === get_post_status( $changeset_post_id ) ) { - if ( ! update_post_meta( $changeset_post_id, '_customize_restore_dismissed', true ) ) { - wp_send_json_error( 'auto_draft_dismissal_failure', 500 ); - } else { + if ( empty( $changeset_post_id ) || 'auto-draft' === get_post_status( $changeset_post_id ) ) { + $changeset_autodraft_posts = $this->get_changeset_posts( array( + 'post_status' => 'auto-draft', + 'exclude_restore_dismissed' => true, + 'posts_per_page' => -1, + ) ); + $dismissed = 0; + foreach ( $changeset_autodraft_posts as $autosave_autodraft_post ) { + if ( $autosave_autodraft_post->ID === $changeset_post_id ) { + continue; + } + if ( update_post_meta( $autosave_autodraft_post->ID, '_customize_restore_dismissed', true ) ) { + $dismissed++; + } + } + if ( $dismissed > 0 ) { wp_send_json_success( 'auto_draft_dismissed' ); + } else { + wp_send_json_error( 'no_autosave_to_delete', 404 ); } } else { $revision = wp_get_post_autosave( $changeset_post_id );