From 83b059aa1927897e5c7394c35d3aebac5b34f2d1 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 18 Oct 2016 20:04:36 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@38810 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/customize.php | 37 +- src/wp-admin/js/customize-controls.js | 1114 ++++++++++---- src/wp-admin/js/customize-widgets.js | 2 +- src/wp-includes/admin-bar.php | 15 + .../class-wp-customize-manager.php | 1287 +++++++++++++++-- .../class-wp-customize-nav-menus.php | 27 +- .../class-wp-customize-widgets.php | 11 +- .../class-wp-customize-selective-refresh.php | 2 - .../class-wp-customize-theme-control.php | 4 +- src/wp-includes/default-filters.php | 2 + src/wp-includes/functions.php | 17 + src/wp-includes/functions.wp-scripts.php | 2 +- src/wp-includes/js/customize-base.js | 50 +- src/wp-includes/js/customize-loader.js | 13 + .../js/customize-preview-nav-menus.js | 27 +- .../js/customize-preview-widgets.js | 5 + src/wp-includes/js/customize-preview.js | 568 +++++++- .../js/customize-selective-refresh.js | 10 +- src/wp-includes/post.php | 45 + src/wp-includes/script-loader.php | 2 +- src/wp-includes/theme.php | 142 +- tests/phpunit/tests/adminbar.php | 33 + tests/phpunit/tests/ajax/CustomizeManager.php | 310 ++++ tests/phpunit/tests/customize/manager.php | 805 ++++++++++- .../customize/selective-refresh-ajax.php | 19 - tests/phpunit/tests/customize/setting.php | 6 + tests/phpunit/tests/functions.php | 18 + tests/phpunit/tests/post.php | 46 + tests/qunit/fixtures/customize-settings.js | 11 + tests/qunit/index.html | 4 + tests/qunit/wp-admin/js/customize-base.js | 19 + tests/qunit/wp-admin/js/customize-controls.js | 72 +- 32 files changed, 4186 insertions(+), 539 deletions(-) create mode 100644 tests/phpunit/tests/ajax/CustomizeManager.php diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php index e45254c74a..0a5350f54c 100644 --- a/src/wp-admin/customize.php +++ b/src/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 ); ?>