From f1ba1918c925510822a48fb83c1e74d22d7f0c46 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 18 Oct 2016 20:05:31 +0000 Subject: [PATCH] Customize: Implement customized state persistence with changesets. Includes infrastructure developed in the Customize Snapshots feature plugin. See https://make.wordpress.org/core/2016/10/12/customize-changesets-technical-design-decisions/ Props westonruter, valendesigns, utkarshpatel, stubgo, lgedeon, ocean90, ryankienstra, mihai2u, dlh, aaroncampbell, jonathanbardo, jorbin. See #28721. See #31089. Fixes #30937. Fixes #31517. Fixes #30028. Fixes #23225. Fixes #34142. Fixes #36485. Built from https://develop.svn.wordpress.org/trunk@38810 git-svn-id: http://core.svn.wordpress.org/trunk@38753 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/customize.php | 37 +- wp-admin/js/customize-controls.js | 1114 ++++++++++---- wp-admin/js/customize-controls.min.js | 4 +- wp-admin/js/customize-widgets.js | 2 +- wp-admin/js/customize-widgets.min.js | 2 +- wp-includes/admin-bar.php | 15 + wp-includes/class-wp-customize-manager.php | 1287 +++++++++++++++-- wp-includes/class-wp-customize-nav-menus.php | 27 +- wp-includes/class-wp-customize-widgets.php | 11 +- .../class-wp-customize-selective-refresh.php | 2 - .../class-wp-customize-theme-control.php | 4 +- wp-includes/default-filters.php | 2 + wp-includes/functions.php | 17 + wp-includes/functions.wp-scripts.php | 2 +- wp-includes/js/customize-base.js | 50 +- wp-includes/js/customize-base.min.js | 2 +- wp-includes/js/customize-loader.js | 13 + wp-includes/js/customize-loader.min.js | 2 +- wp-includes/js/customize-preview-nav-menus.js | 27 +- .../js/customize-preview-nav-menus.min.js | 2 +- wp-includes/js/customize-preview-widgets.js | 5 + .../js/customize-preview-widgets.min.js | 2 +- wp-includes/js/customize-preview.js | 568 +++++++- wp-includes/js/customize-preview.min.js | 2 +- wp-includes/js/customize-selective-refresh.js | 10 +- .../js/customize-selective-refresh.min.js | 2 +- wp-includes/post.php | 45 + wp-includes/script-loader.php | 2 +- wp-includes/theme.php | 142 +- wp-includes/version.php | 2 +- 30 files changed, 2885 insertions(+), 517 deletions(-) diff --git a/wp-admin/customize.php b/wp-admin/customize.php index e45254c74a..0a5350f54c 100644 --- a/wp-admin/customize.php +++ b/wp-admin/customize.php @@ -20,6 +20,31 @@ if ( ! current_user_can( 'customize' ) ) { ); } +/** + * @global WP_Scripts $wp_scripts + * @global WP_Customize_Manager $wp_customize + */ +global $wp_scripts, $wp_customize; + +if ( $wp_customize->changeset_post_id() ) { + if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) { + wp_die( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'Sorry, you are not allowed to edit this changeset.' ) . '

', + 403 + ); + } + if ( in_array( get_post_status( $wp_customize->changeset_post_id() ), array( 'publish', 'trash' ), true ) ) { + wp_die( + '

' . __( 'Cheatin’ uh?' ) . '

' . + '

' . __( 'This changeset has already been published and cannot be further modified.' ) . '

' . + '

' . __( 'Customize New Changes' ) . '

', + 403 + ); + } +} + + wp_reset_vars( array( 'url', 'return', 'autofocus' ) ); if ( ! empty( $url ) ) { $wp_customize->set_preview_url( wp_unslash( $url ) ); @@ -31,12 +56,6 @@ if ( ! empty( $autofocus ) && is_array( $autofocus ) ) { $wp_customize->set_autofocus( wp_unslash( $autofocus ) ); } -/** - * @global WP_Scripts $wp_scripts - * @global WP_Customize_Manager $wp_customize - */ -global $wp_scripts, $wp_customize; - $registered = $wp_scripts->registered; $wp_scripts = new WP_Scripts; $wp_scripts->registered = $registered; @@ -115,7 +134,11 @@ do_action( 'customize_controls_print_scripts' );
is_theme_active() ? __( 'Save & Publish' ) : __( 'Save & Activate' ); - submit_button( $save_text, 'primary save', 'save', false ); + $save_attrs = array(); + if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->publish_posts ) ) { + $save_attrs['style'] = 'display: none'; + } + submit_button( $save_text, 'primary save', 'save', false, $save_attrs ); ?>