Customize API shuffling.

* Rename WP_Customize to WP_Customize_Manager.
 * Move customize-controls.php to wp-admin/customize.php.
 * Make customize.php the formal entry point, rather than admin.php?customize=on.
 * Rename is_current_theme_active() to is_theme_active().
 * Add getters for the theme, settings, controls, and sections properties.
 * Allow customize.php (no ?theme=) to load the active theme. Not used yet.
see #20736.



git-svn-id: http://core.svn.wordpress.org/trunk@20852 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-05-23 17:56:42 +00:00
parent 5a53ce6d28
commit 95e1c32720
4 changed files with 52 additions and 52 deletions

View File

@ -7,10 +7,19 @@
* @since 3.4.0 * @since 3.4.0
*/ */
if ( ! defined( 'ABSPATH' ) ) require_once( './admin.php' );
die; if ( ! current_user_can( 'edit_theme_options' ) )
die( 'Cap check failed' );
global $wp_scripts; global $wp_scripts, $wp_customize;
if ( ! $wp_customize->is_preview() )
die( 'is_preview() failed' );
wp_reset_vars( array( 'theme' ) );
if ( ! $theme )
$theme = get_stylesheet();
$registered = $wp_scripts->registered; $registered = $wp_scripts->registered;
$wp_scripts = new WP_Scripts; $wp_scripts = new WP_Scripts;
@ -33,7 +42,7 @@ do_action( 'customize_controls_enqueue_scripts' );
wp_user_settings(); wp_user_settings();
_wp_admin_html_begin(); _wp_admin_html_begin();
$admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $this->theme->display('Name') ) ) ); $admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
?><title><?php echo $admin_title; ?></title><?php ?><title><?php echo $admin_title; ?></title><?php
do_action( 'customize_controls_print_styles' ); do_action( 'customize_controls_print_styles' );
@ -53,22 +62,22 @@ do_action( 'customize_controls_print_scripts' );
<div id="customize-info" class="customize-section"> <div id="customize-info" class="customize-section">
<div class="customize-section-title"> <div class="customize-section-title">
<span class="preview-notice"><?php _e('You are previewing'); ?></span> <span class="preview-notice"><?php _e('You are previewing'); ?></span>
<strong class="theme-name"><?php echo $this->theme->display('Name'); ?></strong> <strong class="theme-name"><?php echo $wp_customize->theme()->display('Name'); ?></strong>
</div> </div>
<div class="customize-section-content"> <div class="customize-section-content">
<?php if ( $screenshot = $this->theme->get_screenshot() ) : ?> <?php if ( $screenshot = $wp_customize->theme()->get_screenshot() ) : ?>
<img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" /> <img class="theme-screenshot" src="<?php echo esc_url( $screenshot ); ?>" />
<?php endif; ?> <?php endif; ?>
<?php if ( $this->theme->get('Description') ): ?> <?php if ( $wp_customize->theme()->get('Description') ): ?>
<div class="theme-description"><?php echo $this->theme->display('Description'); ?></div> <div class="theme-description"><?php echo $wp_customize->theme()->display('Description'); ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
<div id="customize-theme-controls"><ul> <div id="customize-theme-controls"><ul>
<?php <?php
foreach ( $this->sections as $section ) foreach ( $wp_customize->sections() as $section )
$section->maybe_render(); $section->maybe_render();
?> ?>
</ul></div> </ul></div>
@ -76,7 +85,7 @@ do_action( 'customize_controls_print_scripts' );
<div id="customize-footer-actions" class="wp-full-overlay-footer"> <div id="customize-footer-actions" class="wp-full-overlay-footer">
<?php <?php
$save_text = $this->is_current_theme_active() ? __('Save') : __('Save and Activate'); $save_text = $wp_customize->is_theme_active() ? __('Save') : __('Save and Activate');
submit_button( $save_text, 'primary', 'save', false ); submit_button( $save_text, 'primary', 'save', false );
?> ?>
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" /> <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
@ -108,8 +117,8 @@ do_action( 'customize_controls_print_scripts' );
$settings = array( $settings = array(
'theme' => array( 'theme' => array(
'stylesheet' => $this->get_stylesheet(), 'stylesheet' => $wp_customize->get_stylesheet(),
'active' => $this->is_current_theme_active(), 'active' => $wp_customize->is_theme_active(),
), ),
'url' => array( 'url' => array(
'preview' => esc_url( $preview_url ), 'preview' => esc_url( $preview_url ),
@ -120,14 +129,14 @@ do_action( 'customize_controls_print_scripts' );
'controls' => array(), 'controls' => array(),
); );
foreach ( $this->settings as $id => $setting ) { foreach ( $wp_customize->settings() as $id => $setting ) {
$settings['settings'][ $id ] = array( $settings['settings'][ $id ] = array(
'value' => $setting->js_value(), 'value' => $setting->js_value(),
'transport' => $setting->transport, 'transport' => $setting->transport,
); );
} }
foreach ( $this->controls as $id => $control ) { foreach ( $wp_customize->controls() as $id => $control ) {
$control->to_json(); $control->to_json();
$settings['controls'][ $id ] = $control->json; $settings['controls'][ $id ] = $control->json;
} }

View File

@ -69,6 +69,11 @@ class WP_Plugins_List_Table extends WP_List_Table {
$current = get_site_transient( 'update_plugins' ); $current = get_site_transient( 'update_plugins' );
foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
if ( isset( $current->response[ $plugin_file ] ) ) { if ( isset( $current->response[ $plugin_file ] ) ) {
ob_start();
var_dump( $current->response[ $plugin_file ] );
error_log( $plugin_file . ': ' . ob_get_clean() );
}
if ( ! empty( $current->response[ $plugin_file ] ) ) {
$plugins['all'][ $plugin_file ]['update'] = true; $plugins['all'][ $plugin_file ]['update'] = true;
$plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
} }

View File

@ -7,7 +7,7 @@
* @since 3.4.0 * @since 3.4.0
*/ */
final class WP_Customize { final class WP_Customize_Manager {
protected $theme; protected $theme;
protected $original_stylesheet; protected $original_stylesheet;
@ -32,7 +32,6 @@ final class WP_Customize {
require( ABSPATH . WPINC . '/class-wp-customize-control.php' ); require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
add_action( 'setup_theme', array( $this, 'setup_theme' ) ); add_action( 'setup_theme', array( $this, 'setup_theme' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
add_action( 'wp_ajax_customize_save', array( $this, 'save' ) ); add_action( 'wp_ajax_customize_save', array( $this, 'save' ) );
@ -68,7 +67,7 @@ final class WP_Customize {
* @since 3.4.0 * @since 3.4.0
*/ */
public function setup_theme() { public function setup_theme() {
if ( ! isset( $_REQUEST['customize'] ) || 'on' != $_REQUEST['customize'] ) if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) && ! basename( $_SERVER['PHP_SELF'] ) == 'customize.php' )
return; return;
send_origin_headers(); send_origin_headers();
@ -90,7 +89,7 @@ final class WP_Customize {
// Initialize $theme and $original_stylesheet if they do not yet exist. // Initialize $theme and $original_stylesheet if they do not yet exist.
if ( ! isset( $this->theme ) ) { if ( ! isset( $this->theme ) ) {
$this->theme = wp_get_theme( $_REQUEST['theme'] ); $this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null );
if ( ! $this->theme->exists() ) { if ( ! $this->theme->exists() ) {
$this->theme = false; $this->theme = false;
return; return;
@ -144,12 +143,26 @@ final class WP_Customize {
do_action( 'stop_previewing_theme', $this ); do_action( 'stop_previewing_theme', $this );
} }
/**
* Generic getter.
*
* @since 3.4.0
*
* @return WP_Theme
*/
public function __call( $callee, $args ) {
if ( in_array( $callee, array( 'theme', 'settings', 'controls', 'sections' ) ) )
return $this->$callee;
}
/** /**
* Checks if the current theme is active. * Checks if the current theme is active.
* *
* @since 3.4.0 * @since 3.4.0
*
* @return bool
*/ */
public function is_current_theme_active() { public function is_theme_active() {
return $this->get_stylesheet() == $this->original_stylesheet; return $this->get_stylesheet() == $this->original_stylesheet;
} }
@ -182,7 +195,6 @@ final class WP_Customize {
return $setting->sanitize( $this->_post_values[ $setting->id ] ); return $setting->sanitize( $this->_post_values[ $setting->id ] );
} }
/** /**
* Print javascript settings. * Print javascript settings.
* *
@ -289,32 +301,6 @@ final class WP_Customize {
return $this->theme->display('Name'); return $this->theme->display('Name');
} }
/**
* Trigger save action and load customize controls.
*
* @since 3.4.0
*/
public function admin_init() {
if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
return;
if ( ! isset( $_GET['customize'] ) || 'on' != $_GET['customize'] )
return;
if ( empty( $_GET['theme'] ) )
return;
if ( ! $this->is_preview() )
return;
if ( ! current_user_can( 'edit_theme_options' ) )
return;
include( ABSPATH . WPINC . '/customize-controls.php' );
die;
}
/** /**
* Switch the theme and trigger the save action of each setting. * Switch the theme and trigger the save action of each setting.
* *

View File

@ -1566,7 +1566,7 @@ function check_theme_switched() {
} }
/** /**
* Includes and instantiates the WP_Customize class. * Includes and instantiates the WP_Customize_Manager class.
* *
* Fires when ?customize=on. * Fires when ?customize=on.
* *
@ -1574,12 +1574,12 @@ function check_theme_switched() {
*/ */
function _wp_customize_include() { function _wp_customize_include() {
// Load on themes.php or ?customize=on // Load on themes.php or ?customize=on
if ( ! ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) ) if ( ! ( ( isset( $_REQUEST['customize'] ) && 'on' == $_REQUEST['customize'] ) || 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) )
return; return;
require( ABSPATH . WPINC . '/class-wp-customize.php' ); require( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
// Init Customize class // Init Customize class
$GLOBALS['wp_customize'] = new WP_Customize; $GLOBALS['wp_customize'] = new WP_Customize_Manager;
} }
add_action( 'plugins_loaded', '_wp_customize_include' ); add_action( 'plugins_loaded', '_wp_customize_include' );
@ -1604,5 +1604,5 @@ add_action( 'admin_enqueue_scripts', '_wp_customize_loader_localize' );
* @since 3.4.0 * @since 3.4.0
*/ */
function wp_customize_url( $stylesheet ) { function wp_customize_url( $stylesheet ) {
return esc_url( admin_url( 'admin.php' ) . '?customize=on&theme=' . $stylesheet ); return esc_url( admin_url( 'customize.php' ) . '?theme=' . $stylesheet );
} }