From 9df0620d89e4bba9eac9fb1b625b7d84529dcd46 Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 17 Apr 2012 21:43:47 +0000 Subject: [PATCH] Move to admin.php?customize=on&theme=$stylesheet, rather than juggling both template and stylesheet values. see #19910. Combine the setup_theme() and customize_previewing() methods. Remove the set_template() and set_stylesheet() methods. Add set_theme() method to WP_Customize to store the working WP_Theme object. We will use this for the stylesheet and template. Use the WP_Theme display() method when preparing headers for display, not get() or the deprecate properties. git-svn-id: http://svn.automattic.com/wordpress/trunk@20496 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize.php | 96 ++++++++++-------------------- wp-includes/customize-controls.php | 17 ++---- wp-includes/theme.php | 2 +- 3 files changed, 37 insertions(+), 78 deletions(-) diff --git a/wp-includes/class-wp-customize.php b/wp-includes/class-wp-customize.php index 21ce6031d..d729aab08 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 11661037e..cd28f6c72 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') ) ) ); ?><?php echo $admin_title; ?>"> - - - +
@@ -59,15 +54,15 @@ do_action( 'customize_controls_print_scripts' );
- + theme->display('Name'); ?>
- + theme->get_screenshot() ) : ?> - description ): ?> -
description; ?>
+ theme->get('Description') ): ?> +
theme->display('Description'); ?>
diff --git a/wp-includes/theme.php b/wp-includes/theme.php index ce9bb55f5..b41ec3f23 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1601,5 +1601,5 @@ add_action( 'admin_enqueue_scripts', '_wp_customize_loader_localize' ); * @since 3.4.0 */ function wp_customize_url( $stylesheet, $template ) { - return esc_url( admin_url( 'admin.php' ) . '?customize=on&template=' . $template . '&stylesheet=' . $stylesheet ); + return esc_url( admin_url( 'admin.php' ) . '?customize=on&theme=' . $stylesheet ); } \ No newline at end of file