From bc99ad372e810c3978121e45b3f9d76c1dc9a6b1 Mon Sep 17 00:00:00 2001 From: koopersmith Date: Wed, 16 May 2012 05:55:54 +0000 Subject: [PATCH] Theme Customizer: Properly change state when theme is switched. fixes #20610, see #19910. * Causes the Manage Themes page to refresh if the customizer is closed after the active theme is switched. * Changes the text of the 'Save and Activate' button once the theme has been activated. * Improves the naming of the customize control settings. * Add events to customize.Loader and make callbacks more flexible. * Makes the customize-loader l10n compatible with non-admin settings. * Adds WP_Customize->is_current_theme_active(). * Minor style corrections, including jQuery.attr/prop changes. git-svn-id: http://core.svn.wordpress.org/trunk@20802 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/theme.dev.js | 29 +++++++++++ wp-includes/class-wp-customize.php | 9 ++++ wp-includes/customize-controls.php | 15 ++++-- wp-includes/js/customize-controls.dev.js | 34 +++++++++++-- wp-includes/js/customize-loader.dev.js | 63 +++++++++++++++++------- wp-includes/js/customize-preview.dev.js | 4 +- wp-includes/script-loader.php | 5 +- wp-includes/theme.php | 10 ++-- 8 files changed, 133 insertions(+), 36 deletions(-) diff --git a/wp-admin/js/theme.dev.js b/wp-admin/js/theme.dev.js index 2110feb81..ede9274bd 100644 --- a/wp-admin/js/theme.dev.js +++ b/wp-admin/js/theme.dev.js @@ -18,6 +18,35 @@ jQuery( function($) { }); }); +/** + * Theme Customizer + * + * Ensures the themes page is refreshed if the customizer switches the theme. + */ +jQuery( function($) { + var Loader, activated; + + if ( typeof wp === 'undefined' || ! wp.customize || ! ( Loader = wp.customize.Loader ) ) + return; + + // Strip the current URL of its query string and hash, add activated query string. + activated = window.location.href.replace(/[#?].*$/, '') + '?activated=true'; + + // When an instance of the customizer is loaded... + Loader.bind( 'open', function() { + + // If the customizer triggers a theme switched event, + // load the activated page when the customizer is closed. + Loader.messenger.bind( 'switched', function() { + + Loader.unbind( 'close', Loader.overlay.hide ); + Loader.bind( 'close', function() { + window.location = activated; + }); + }); + }); +}); + /** * Theme Install * diff --git a/wp-includes/class-wp-customize.php b/wp-includes/class-wp-customize.php index ffae10619..9eb280ff3 100644 --- a/wp-includes/class-wp-customize.php +++ b/wp-includes/class-wp-customize.php @@ -144,6 +144,15 @@ final class WP_Customize { do_action( 'stop_previewing_theme', $this ); } + /** + * Checks if the current theme is active. + * + * @since 3.4.0 + */ + public function is_current_theme_active() { + return $this->get_stylesheet() == $this->original_stylesheet; + } + /** * Register styles/scripts and initialize the preview of each setting * diff --git a/wp-includes/customize-controls.php b/wp-includes/customize-controls.php index 225382997..0fd9b030d 100644 --- a/wp-includes/customize-controls.php +++ b/wp-includes/customize-controls.php @@ -76,7 +76,7 @@ do_action( 'customize_controls_print_scripts' );