Customize: Extend changesets to support autosave revisions with restoration notifications, and introduce a new default linear history mode for saved changesets (with a filter for opt-in to changeset branching).
* Autosaved changes made on top of `auto-draft` changesets get written on top of the `auto-draft` itself, similar to how autosaves for posts will overwrite post drafts. * Autosaved changes made to saved changesets (e.g. `draft`, `future`) will be placed into an autosave revision for that changeset and that user. * Opening the Customizer will now prompt the user to restore their most recent auto-draft changeset; if notification is dismissed or ignored then the auto-draft will be marked as dismissed and will not be prompted to user in a notification again. * Customizer will no longer automatically supply the `changeset_uuid` param in the `customize.php` URL when branching changesets are not active. * If user closes Customizer explicitly via clicking on X link, then autosave auto-draft/autosave will be dismissed so as to not be prompted again. * If there is a changeset already saved as a `draft` or `future` (UI is forthcoming) then this changeset will now be autoloaded for the user to keep making additional changes. This is the linear model for changesets. * To restore the previous behavior of the Customizer where each session started a new changeset, regardless of whether or not there was an existing changeset saved, there is now a `customize_changeset_branching` hook which can be filtered to return `true`. * `wp.customize.requestChangesetUpdate()` now supports a second with options including `autosave`, `title`, and `date`. * The window `blur` event for `customize.php` has been replaced with a `visibilitychange` event to reduce autosave requests when clicking into preview window. * Adds `autosaved` and `branching` args to `WP_Customize_Manager`. * The `changeset_uuid` param for `WP_Customize_Manager` is extended to recognize a `false` value which causes the Customizer to defer identifying the UUID until `after_setup_theme` in the new `WP_Customize_Manager::establish_loaded_changeset()` method. * A new `customize_autosaved` query parameter can now be supplied which is passed into the `autosaved` arg in `WP_Customize_Manager`; this option is an opt-in to source data from the autosave revision, allowing a user to restore autosaved changes. Props westonruter, dlh, sayedwp, JoshuaWold, melchoyce. See #39896. Built from https://develop.svn.wordpress.org/trunk@41597 git-svn-id: http://core.svn.wordpress.org/trunk@41430 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -2787,15 +2787,17 @@ function _wp_customize_include() {
|
||||
* called before wp_magic_quotes() gets called. Besides this fact, none of
|
||||
* the values should contain any characters needing slashes anyway.
|
||||
*/
|
||||
$keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel' );
|
||||
$keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' );
|
||||
$input_vars = array_merge(
|
||||
wp_array_slice_assoc( $_GET, $keys ),
|
||||
wp_array_slice_assoc( $_POST, $keys )
|
||||
);
|
||||
|
||||
$theme = null;
|
||||
$changeset_uuid = null;
|
||||
$changeset_uuid = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists.
|
||||
$messenger_channel = null;
|
||||
$autosaved = null;
|
||||
$branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter.
|
||||
|
||||
if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) {
|
||||
$changeset_uuid = sanitize_key( $input_vars['changeset_uuid'] );
|
||||
@@ -2809,6 +2811,11 @@ function _wp_customize_include() {
|
||||
} elseif ( isset( $input_vars['customize_theme'] ) ) {
|
||||
$theme = $input_vars['customize_theme'];
|
||||
}
|
||||
|
||||
if ( ! empty( $input_vars['customize_autosaved'] ) ) {
|
||||
$autosaved = true;
|
||||
}
|
||||
|
||||
if ( isset( $input_vars['customize_messenger_channel'] ) ) {
|
||||
$messenger_channel = sanitize_key( $input_vars['customize_messenger_channel'] );
|
||||
}
|
||||
@@ -2830,7 +2837,7 @@ function _wp_customize_include() {
|
||||
$settings_previewed = ! $is_customize_save_action;
|
||||
|
||||
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
|
||||
$GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed' ) );
|
||||
$GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user