diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 0e4e5d0238..4bc94ae88c 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -8248,7 +8248,7 @@ // Set up initial notifications. (function() { - var removedQueryParams = []; + var removedQueryParams = [], autosaveDismissed = false; /** * Obtain the URL to restore the autosave. @@ -8294,6 +8294,25 @@ history.replaceState( {}, document.title, urlParser.href ); } + /** + * Dismiss autosave. + * + * @returns {void} + */ + function dismissAutosave() { + if ( autosaveDismissed ) { + return; + } + wp.ajax.post( 'customize_dismiss_autosave_or_lock', { + wp_customize: 'on', + customize_theme: api.settings.theme.stylesheet, + customize_changeset_uuid: api.settings.changeset.uuid, + nonce: api.settings.nonce.dismiss_autosave_or_lock, + dismiss_autosave: true + } ); + autosaveDismissed = true; + } + /** * Add notification regarding the availability of an autosave to restore. * @@ -8319,15 +8338,7 @@ } ); // Handle dismissal of notice. - li.find( '.notice-dismiss' ).on( 'click', function() { - wp.ajax.post( 'customize_dismiss_autosave_or_lock', { - wp_customize: 'on', - customize_theme: api.settings.theme.stylesheet, - customize_changeset_uuid: api.settings.changeset.uuid, - nonce: api.settings.nonce.dismiss_autosave_or_lock, - dismiss_autosave: true - } ); - } ); + li.find( '.notice-dismiss' ).on( 'click', dismissAutosave ); return li; } @@ -8335,6 +8346,7 @@ // Remove the notification once the user starts making changes. onStateChange = function() { + dismissAutosave(); api.notifications.remove( code ); api.unbind( 'change', onStateChange ); api.state( 'changesetStatus' ).unbind( onStateChange );