Theme Customizer: Numerous API refinements and bugfixes. Add a theme_supports check for header_textcolor. see #19910.

* prepare_controls() now removes any settings and sections that return false for check_capabilities().
* Added maybe_render() methods to both settings and sections that call the protected render() methods.
* Stop firing front-end preview functionality when rendering the controls.
* Merged the WP_Customize_Setting->_render_type() method into WP_Customize_Setting->render().
* Removed the 'customize_render_control-' hook; use 'customize_render_setting' instead.
* Added a  property to sections and settings so they no longer rely on the  global. Hooray for dependency injection.
* Shifted calls to WP_Customize_Setting->enqueue() to the 'customize_controls_enqueue_scripts' action.
* Added a theme_supports check for the header_textcolor setting.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20248 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
koopersmith
2012-03-21 22:55:43 +00:00
parent 3015057d58
commit dbd50b0972
4 changed files with 106 additions and 69 deletions

View File

@@ -8,6 +8,7 @@
*/
class WP_Customize_Setting {
public $manager;
public $id;
public $priority = 10;
public $section = '';
@@ -35,13 +36,14 @@ class WP_Customize_Setting {
* theme mod or option name.
* @param array $args Setting arguments.
*/
function __construct( $id, $args = array() ) {
function __construct( $manager, $id, $args = array() ) {
$keys = array_keys( get_class_vars( __CLASS__ ) );
foreach ( $keys as $key ) {
if ( isset( $args[ $key ] ) )
$this->$key = $args[ $key ];
}
$this->manager = $manager;
$this->id = $id;
// Parse the ID for array keys.
@@ -265,15 +267,13 @@ class WP_Customize_Setting {
* @return bool False if theme doesn't support the setting or user can't change setting, otherwise true.
*/
public final function check_capabilities() {
global $customize;
if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
return false;
if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) )
return false;
$section = $customize->get_section( $this->section );
$section = $this->manager->get_section( $this->section );
if ( isset( $section ) && ! $section->check_capabilities() )
return false;
@@ -281,15 +281,16 @@ class WP_Customize_Setting {
}
/**
* Render the control.
* Check capabiliites and render the control.
*
* @since 3.4.0
*/
public final function _render() {
public final function maybe_render() {
if ( ! $this->check_capabilities() )
return;
do_action( 'customize_render_' . $this->id );
do_action( 'customize_render_setting', $this );
do_action( 'customize_render_setting_' . $this->id, $this );
$this->render();
}
@@ -300,39 +301,6 @@ class WP_Customize_Setting {
* @since 3.4.0
*/
protected function render() {
$this->_render_type();
}
/**
* Retrieve the name attribute for an input.
*
* @since 3.4.0
*
* @return string The name.
*/
public final function get_name() {
return self::name_prefix . esc_attr( $this->id );
}
/**
* Echo the HTML name attribute for an input.
*
* @since 3.4.0
*
* @return string The HTML name attribute.
*/
public final function name() {
echo 'name="' . $this->get_name() . '"';
}
/**
* Render the control type.
*
* @todo Improve value and checked attributes.
*
* @since 3.4.0
*/
public final function _render_type() {
switch( $this->control ) {
case 'text':
?>
@@ -414,12 +382,31 @@ class WP_Customize_Setting {
</label>
<?php
break;
default:
do_action( 'customize_render_control-' . $this->control, $this );
}
}
/**
* Retrieve the name attribute for an input.
*
* @since 3.4.0
*
* @return string The name.
*/
public final function get_name() {
return self::name_prefix . esc_attr( $this->id );
}
/**
* Echo the HTML name attribute for an input.
*
* @since 3.4.0
*
* @return string The HTML name attribute.
*/
public final function name() {
echo 'name="' . $this->get_name() . '"';
}
/**
* Multidimensional helper function.
*