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
This commit is contained in:
parent
565300e1cd
commit
9df0620d89
|
@ -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();
|
||||
|
|
|
@ -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') ) ) );
|
||||
?><title><?php echo $admin_title; ?></title><?php
|
||||
|
||||
do_action( 'customize_controls_print_styles' );
|
||||
|
@ -47,9 +44,7 @@ do_action( 'customize_controls_print_scripts' );
|
|||
<form id="customize-controls" method="post" class="wrap wp-full-overlay-sidebar" target="_parent" action="<?php echo esc_url( add_query_arg( 'save_customize_controls', '1', admin_url( 'themes.php' ) ) ); ?>">
|
||||
<?php wp_nonce_field( 'customize_controls' ); ?>
|
||||
<input type="hidden" name="customize" value="on" />
|
||||
<input type="hidden" id="customize-template" name="template" value="<?php echo esc_attr( $theme['Template'] ); ?>" />
|
||||
<input type="hidden" id="customize-stylesheet" name="stylesheet" value="<?php echo esc_attr( $theme['Stylesheet'] ); ?>" />
|
||||
|
||||
<input type="hidden" name="theme" value="<?php echo esc_attr( $this->get_stylesheet() ); ?>" />
|
||||
<div id="customize-header-actions" class="customize-section wp-full-overlay-header">
|
||||
<a class="back" href="<?php echo esc_url( admin_url( 'themes.php' ) ); ?>">
|
||||
<?php printf( __( '← Return to %s' ), __('Manage Themes') ); ?>
|
||||
|
@ -59,15 +54,15 @@ do_action( 'customize_controls_print_scripts' );
|
|||
<div id="customize-info" class="customize-section">
|
||||
<div class="customize-section-title">
|
||||
<span class="preview-notice"><?php _e('You are previewing'); ?></span>
|
||||
<strong class="theme-name"><?php echo $theme['Name']; ?></strong>
|
||||
<strong class="theme-name"><?php echo $this->theme->display('Name'); ?></strong>
|
||||
</div>
|
||||
<div class="customize-section-content">
|
||||
<?php if ( $screenshot ) : ?>
|
||||
<?php if ( $screenshot = $this->theme->get_screenshot() ) : ?>
|
||||
<img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $theme->description ): ?>
|
||||
<div class="theme-description"><?php echo $theme->description; ?></div>
|
||||
<?php if ( $this->theme->get('Description') ): ?>
|
||||
<div class="theme-description"><?php echo $this->theme->display('Description'); ?></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 );
|
||||
}
|
Loading…
Reference in New Issue