diff --git a/wp-admin/customize.php b/wp-admin/customize.php index d60c99330d..3e6a67508a 100644 --- a/wp-admin/customize.php +++ b/wp-admin/customize.php @@ -161,7 +161,7 @@ do_action( 'customize_controls_print_scripts' ); 'url' => array( 'preview' => esc_url( $url ? $url : home_url( '/' ) ), 'parent' => esc_url( admin_url() ), - 'activated' => esc_url( admin_url( 'themes.php?activated=true' ) ), + 'activated' => admin_url( 'themes.php?activated=true&previewed' ), 'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ), 'allowed' => array_map( 'esc_url', $allowed_urls ), 'isCrossDomain' => $cross_domain, diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 6353235d61..c892705ee4 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -92,18 +92,6 @@ wp_enqueue_script( 'customize-loader' ); require_once('./admin-header.php'); ?> - -

- -

widgets settings screen to configure them.'), admin_url( 'widgets.php' ) ); ?>

-

Visit site' ), home_url( '/' ) ); ?>

-

- -
@@ -114,6 +102,20 @@ if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?> +

+ +

Visit site.' ), home_url( '/' ) ); ?>

+ +

widgets settings screen to configure them.'), admin_url( 'widgets.php' ) ); ?>

+

Visit site' ), home_url( '/' ) ); ?>

+

+get_screenshot(); diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index a73654e060..47cb30dcf0 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -72,10 +72,13 @@ final class WP_Customize_Manager { * * @since 3.4.0 */ - private function wp_die( $ajax_message, $message ) { + protected function wp_die( $ajax_message, $message = null ) { if ( $this->doing_ajax() ) wp_die( $ajax_message ); + if ( ! $message ) + $message = __( 'Cheatin’ uh?' ); + wp_die( $message ); } @@ -98,29 +101,45 @@ final class WP_Customize_Manager { * @since 3.4.0 */ public function setup_theme() { + send_origin_headers(); + if ( is_admin() && ! $this->doing_ajax() ) auth_redirect(); - elseif ( $this->doing_ajax() && ! is_user_logged_in()) - wp_die( 0 ); + elseif ( $this->doing_ajax() && ! is_user_logged_in() ) + $this->wp_die( 0 ); - send_origin_headers(); + show_admin_bar( false ); + + if ( ! current_user_can( 'edit_theme_options' ) ) + $this->wp_die( -1 ); $this->original_stylesheet = get_stylesheet(); $this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null ); - // You can't preview a theme if it doesn't exist, or if it is not allowed (unless active). - if ( ! $this->theme->exists() ) - $this->wp_die( -1, __( 'Cheatin’ uh?' ) ); + if ( $this->is_theme_active() ) { + // Once the theme is loaded, we'll validate it. + add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) ); + } else { + if ( ! current_user_can( 'switch_themes' ) ) + $this->wp_die( -1 ); - if ( $this->theme->get_stylesheet() != get_stylesheet() && ( ! $this->theme()->is_allowed() || ! current_user_can( 'switch_themes' ) ) ) - $this->wp_die( -1, __( 'Cheatin’ uh?' ) ); + // If the theme isn't active, you can't preview it if it is not allowed or has errors. + if ( $this->theme()->errors() ) + $this->wp_die( -1 ); - if ( ! current_user_can( 'edit_theme_options' ) ) - $this->wp_die( -1, __( 'Cheatin’ uh?' ) ); + if ( ! $this->theme()->is_allowed() ) + $this->wp_die( -1 ); + } $this->start_previewing_theme(); - show_admin_bar( false ); + } + + function after_setup_theme() { + if ( ! $this->doing_ajax() && ! validate_current_theme() ) { + wp_redirect( 'themes.php?broken=true' ); + exit; + } } /** @@ -137,17 +156,19 @@ final class WP_Customize_Manager { $this->previewing = true; - add_filter( 'template', array( $this, 'get_template' ) ); - add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); - add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) ); - - // @link: http://core.trac.wordpress.org/ticket/20027 - add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) ); - add_filter( 'pre_option_template', array( $this, 'get_template' ) ); - - // Handle custom theme roots. - add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) ); - add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); + if ( ! $this->is_theme_active() ) { + add_filter( 'template', array( $this, 'get_template' ) ); + add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); + add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) ); + + // @link: http://core.trac.wordpress.org/ticket/20027 + add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) ); + add_filter( 'pre_option_template', array( $this, 'get_template' ) ); + + // Handle custom theme roots. + add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) ); + add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); + } do_action( 'start_previewing_theme', $this ); } @@ -165,17 +186,19 @@ final class WP_Customize_Manager { $this->previewing = false; - remove_filter( 'template', array( $this, 'get_template' ) ); - remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); - remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) ); - - // @link: http://core.trac.wordpress.org/ticket/20027 - remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) ); - remove_filter( 'pre_option_template', array( $this, 'get_template' ) ); - - // Handle custom theme roots. - remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) ); - remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); + if ( ! $this->is_theme_active() ) { + remove_filter( 'template', array( $this, 'get_template' ) ); + remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); + remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) ); + + // @link: http://core.trac.wordpress.org/ticket/20027 + remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) ); + remove_filter( 'pre_option_template', array( $this, 'get_template' ) ); + + // Handle custom theme roots. + remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) ); + remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); + } do_action( 'stop_previewing_theme', $this ); } @@ -389,7 +412,7 @@ final class WP_Customize_Manager { * @return string Template name. */ public function get_template() { - return $this->theme->get_template(); + return $this->theme()->get_template(); } /** @@ -400,7 +423,7 @@ final class WP_Customize_Manager { * @return string Stylesheet name. */ public function get_stylesheet() { - return $this->theme->get_stylesheet(); + return $this->theme()->get_stylesheet(); } /** @@ -433,7 +456,7 @@ final class WP_Customize_Manager { * @return string Theme name. */ public function current_theme( $current_theme ) { - return $this->theme->display('Name'); + return $this->theme()->display('Name'); } /** @@ -448,7 +471,7 @@ final class WP_Customize_Manager { check_ajax_referer( 'customize_controls-' . $this->get_stylesheet(), 'nonce' ); // Do we have to switch themes? - if ( $this->get_stylesheet() != $this->original_stylesheet ) { + if ( ! $this->is_theme_active() ) { // Temporarily stop previewing the theme to allow switch_themes() // to operate properly. $this->stop_previewing_theme(); @@ -462,22 +485,9 @@ final class WP_Customize_Manager { $setting->save(); } - add_action( 'admin_notices', array( $this, '_save_feedback' ) ); - die; } - /** - * Show an admin notice after settings are saved. - * - * @since 3.4.0 - */ - public function _save_feedback() { - ?> -

Visit site.' ), home_url( '/' ) ); ?>

-