diff --git a/wp-includes/class-wp-customize.php b/wp-includes/class-wp-customize.php index 21ce6031d0..d729aab087 100644 --- a/wp-includes/class-wp-customize.php +++ b/wp-includes/class-wp-customize.php @@ -8,9 +8,7 @@ */ final class WP_Customize { - protected $template; - protected $stylesheet; - protected $original_template; + protected $theme; protected $original_stylesheet; protected $previewing = false; @@ -29,11 +27,10 @@ final class WP_Customize { require( ABSPATH . WPINC . '/class-wp-customize-section.php' ); require( ABSPATH . WPINC . '/class-wp-customize-control.php' ); - add_action( 'setup_theme', array( $this, 'setup_theme' ) ); + add_action( 'setup_theme', array( $this, 'customize_previewing' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); - add_action( 'customize_previewing', array( $this, 'customize_previewing' ) ); add_action( 'customize_register', array( $this, 'register_controls' ) ); add_action( 'customize_controls_init', array( $this, 'prepare_controls' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) ); @@ -59,32 +56,22 @@ final class WP_Customize { /** * Start preview and customize theme. - * Check if customize query variable exist. * - * @since 3.4.0 - */ - public function setup_theme() { - if ( ! isset( $_REQUEST['customize'] ) || 'on' != $_REQUEST['customize'] ) - return; - - if ( ! $this->set_stylesheet() || isset( $_REQUEST['save_customize_controls'] ) ) - return; - - $this->previewing = true; - do_action( 'customize_previewing' ); - } - - /** - * Init filters to filter theme options. + * Check if customize query variable exist. Init filters to filter the current theme. * * @since 3.4.0 */ public function customize_previewing() { - global $wp_theme_directories; + if ( ! isset( $_REQUEST['customize'] ) || 'on' != $_REQUEST['customize'] ) + return; + + if ( ! $this->set_theme() || isset( $_REQUEST['save_customize_controls'] ) ) + return; + + $this->previewing = true; show_admin_bar( false ); - $this->original_template = get_template(); $this->original_stylesheet = get_stylesheet(); add_filter( 'template', array( $this, 'get_template' ) ); @@ -96,10 +83,10 @@ final class WP_Customize { add_filter( 'pre_option_template', array( $this, 'get_template' ) ); // Handle custom theme roots. - if ( count( $wp_theme_directories ) > 1 ) { - add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) ); - add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); - } + add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) ); + add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) ); + + do_action( 'customize_previewing' ); } /** @@ -172,24 +159,6 @@ final class WP_Customize { return (bool) $this->previewing; } - /** - * Set the template name of the previewed theme. - * - * @since 3.4.0 - * - * @return bool|string Template name. - */ - public function set_template() { - if ( ! empty( $this->template ) ) - return $this->template; - - $template = preg_replace('|[^a-z0-9_./-]|i', '', $_REQUEST['template'] ); - if ( validate_file( $template ) ) - return false; - - return $this->template = $template; - } - /** * Set the stylesheet name of the previewed theme. * @@ -197,23 +166,15 @@ final class WP_Customize { * * @return bool|string Stylesheet name. */ - public function set_stylesheet() { - if ( ! empty( $this->stylesheet ) ) - return $this->stylesheet; + public function set_theme() { + if ( isset( $this->theme ) ) + return $this->theme; - $this->set_template(); - if ( empty( $this->template ) ) - return false; - - if ( empty( $_REQUEST['stylesheet'] ) ) { - $stylesheet = $this->template; - } else { - $stylesheet = preg_replace( '|[^a-z0-9_./-]|i', '', $_REQUEST['stylesheet'] ); - if ( $stylesheet != $this->template && validate_file( $stylesheet ) ) - return false; - } - return $this->stylesheet = $stylesheet; + $this->theme = wp_get_theme( $_REQUEST['theme'] ); + if ( ! $this->theme->exists() ) + $this->theme = false; + return $this->theme; } /** @@ -224,7 +185,7 @@ final class WP_Customize { * @return string Template name. */ public function get_template() { - return $this->template; + return $this->theme->get_template(); } /** @@ -235,7 +196,7 @@ final class WP_Customize { * @return string Stylesheet name. */ public function get_stylesheet() { - return $this->stylesheet; + return $this->theme->get_stylesheet(); } /** @@ -246,7 +207,7 @@ final class WP_Customize { * @return string Theme root. */ public function get_template_root() { - return get_raw_theme_root( $this->template, true ); + return get_raw_theme_root( $this->get_template(), true ); } /** @@ -257,7 +218,7 @@ final class WP_Customize { * @return string Theme root. */ public function get_stylesheet_root() { - return get_raw_theme_root( $this->stylesheet, true ); + return get_raw_theme_root( $this->get_stylesheet(), true ); } /** @@ -268,7 +229,7 @@ final class WP_Customize { * @return string Theme name. */ public function current_theme( $current_theme ) { - return wp_get_theme( $this->stylesheet )->get('Name'); + return $this->theme->display('Name'); } /** @@ -286,6 +247,9 @@ final class WP_Customize { if ( ! isset( $_GET['customize'] ) || 'on' != $_GET['customize'] ) return; + if ( empty( $_GET['theme'] ) ) + return; + if ( ! $this->is_preview() ) return; @@ -308,7 +272,7 @@ final class WP_Customize { check_admin_referer( 'customize_controls' ); - if ( ! $this->set_stylesheet() ) + if ( ! $this->set_theme() ) return; $active_template = get_template(); diff --git a/wp-includes/customize-controls.php b/wp-includes/customize-controls.php index 11661037ea..cd28f6c72e 100644 --- a/wp-includes/customize-controls.php +++ b/wp-includes/customize-controls.php @@ -27,16 +27,13 @@ wp_enqueue_style( 'customize-controls' ); do_action( 'customize_controls_enqueue_scripts' ); -$theme = wp_get_theme(); -$screenshot = $theme->get_screenshot(); - // Let's roll. @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); wp_user_settings(); _wp_admin_html_begin(); -$admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $theme['Name'] ) ) ); +$admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $this->theme->display('Name') ) ) ); ?>