WordPress/wp-includes/class-wp-customize-section.php
koopersmith 30d798ec8d Create WP_Customize_Control to separate the process of rendering a control from fetching, previewing, and saving its values. see #19910.
Many-to-many mapping between settings and controls.
* Settings and controls have been separated in both the PHP (WP_Customize_Setting, WP_Customize_Control) and the JS (wp.customize.Setting, wp.customize.Control).
* While most settings are tied to a single control, some require multiple controls. The 'header_textcolor' control is a good example: to hide the header text, header_textcolor is set to 'blank'.

Add 'Display Header Text' control.

A handful of miscellaneous bugfixes along the way.

Notes:
* Controls should be separated out a bit more; juggling type-specific arguments in the switch statement is rather inelegant.
* Page dropdowns are currently inactive and need to be re-linked.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20295 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2012-03-28 04:14:09 +00:00

95 lines
2.1 KiB
PHP

<?php
/**
* Customize Section Class
*
* @package WordPress
* @subpackage Customize
* @since 3.4.0
*/
class WP_Customize_Section {
public $manager;
public $id;
public $priority = 10;
public $capability = 'edit_theme_options';
public $theme_supports = '';
public $title = '';
public $description = '';
public $controls;
/**
* Constructor.
*
* @since 3.4.0
*
* @param string $id An specific ID of the section.
* @param array $args Section arguments.
*/
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;
$this->controls = array(); // Users cannot customize the $controls array.
return $this;
}
/**
* Check if the theme supports the section and check user capabilities.
*
* @since 3.4.0
*
* @return bool False if theme doesn't support the section or user doesn't have the capability.
*/
public final function check_capabilities() {
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;
return true;
}
/**
* Check capabiliites and render the section.
*
* @since 3.4.0
*/
public final function maybe_render() {
if ( ! $this->check_capabilities() )
return;
do_action( 'customize_render_section', $this );
do_action( 'customize_render_section_' . $this->id );
$this->render();
}
/**
* Render the section.
*
* @since 3.4.0
*/
protected function render() {
?>
<li id="customize-section-<?php echo esc_attr( $this->id ); ?>" class="control-section customize-section">
<h3 class="customize-section-title" title="<?php echo esc_attr( $this->description ); ?>"><?php echo esc_html( $this->title ); ?></h3>
<ul class="customize-section-content">
<?php
foreach ( $this->controls as $control )
$control->maybe_render();
?>
</ul>
</li>
<?php
}
}