Add JS templates for Customizer Panels and Sections.
This extends the approach taken for Customizer Controls in #29572. Props celloexpressions, westonruter, ocean90. See #30737. Built from https://develop.svn.wordpress.org/trunk@32658 git-svn-id: http://core.svn.wordpress.org/trunk@32628 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -60,7 +60,25 @@ final class WP_Customize_Manager {
|
||||
protected $customized;
|
||||
|
||||
/**
|
||||
* Controls that may be rendered from JS templates.
|
||||
* Panel types that may be rendered from JS templates.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected $registered_panel_types = array();
|
||||
|
||||
/**
|
||||
* Section types that may be rendered from JS templates.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
protected $registered_section_types = array();
|
||||
|
||||
/**
|
||||
* Control types that may be rendered from JS templates.
|
||||
*
|
||||
* @since 4.1.0
|
||||
* @access protected
|
||||
@@ -612,19 +630,29 @@ final class WP_Customize_Manager {
|
||||
}
|
||||
|
||||
foreach ( $this->settings as $id => $setting ) {
|
||||
$settings['values'][ $id ] = $setting->js_value();
|
||||
if ( $setting->check_capabilities() ) {
|
||||
$settings['values'][ $id ] = $setting->js_value();
|
||||
}
|
||||
}
|
||||
foreach ( $this->panels as $id => $panel ) {
|
||||
$settings['activePanels'][ $id ] = $panel->active();
|
||||
foreach ( $panel->sections as $id => $section ) {
|
||||
$settings['activeSections'][ $id ] = $section->active();
|
||||
foreach ( $this->panels as $panel_id => $panel ) {
|
||||
if ( $panel->check_capabilities() ) {
|
||||
$settings['activePanels'][ $panel_id ] = $panel->active();
|
||||
foreach ( $panel->sections as $section_id => $section ) {
|
||||
if ( $section->check_capabilities() ) {
|
||||
$settings['activeSections'][ $section_id ] = $section->active();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $this->sections as $id => $section ) {
|
||||
$settings['activeSections'][ $id ] = $section->active();
|
||||
if ( $section->check_capabilities() ) {
|
||||
$settings['activeSections'][ $id ] = $section->active();
|
||||
}
|
||||
}
|
||||
foreach ( $this->controls as $id => $control ) {
|
||||
$settings['activeControls'][ $id ] = $control->active();
|
||||
if ( $control->check_capabilities() ) {
|
||||
$settings['activeControls'][ $id ] = $control->active();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -964,6 +992,34 @@ final class WP_Customize_Manager {
|
||||
unset( $this->panels[ $id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a customize panel type.
|
||||
*
|
||||
* Registered types are eligible to be rendered via JS and created dynamically.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $panel Name of a custom panel which is a subclass of
|
||||
* {@see WP_Customize_Panel}.
|
||||
*/
|
||||
public function register_panel_type( $panel ) {
|
||||
$this->registered_panel_types[] = $panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render JS templates for all registered panel types.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function render_panel_templates() {
|
||||
foreach ( $this->registered_panel_types as $panel_type ) {
|
||||
$panel = new $panel_type( $this, 'temp', array() );
|
||||
$panel->print_template();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a customize section.
|
||||
*
|
||||
@@ -1005,6 +1061,34 @@ final class WP_Customize_Manager {
|
||||
unset( $this->sections[ $id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a customize section type.
|
||||
*
|
||||
* Registered types are eligible to be rendered via JS and created dynamically.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $section Name of a custom section which is a subclass of
|
||||
* {@see WP_Customize_Section}.
|
||||
*/
|
||||
public function register_section_type( $section ) {
|
||||
$this->registered_section_types[] = $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render JS templates for all registered section types.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @access public
|
||||
*/
|
||||
public function render_section_templates() {
|
||||
foreach ( $this->registered_section_types as $section_type ) {
|
||||
$section = new $section_type( $this, 'temp', array() );
|
||||
$section->print_template();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a customize control.
|
||||
*
|
||||
@@ -1176,7 +1260,10 @@ final class WP_Customize_Manager {
|
||||
*/
|
||||
public function register_controls() {
|
||||
|
||||
/* Control Types (custom control classes) */
|
||||
/* Panel, Section, and Control Types */
|
||||
$this->register_panel_type( 'WP_Customize_Panel' );
|
||||
$this->register_section_type( 'WP_Customize_Section' );
|
||||
$this->register_section_type( 'WP_Customize_Sidebar_Section' );
|
||||
$this->register_control_type( 'WP_Customize_Color_Control' );
|
||||
$this->register_control_type( 'WP_Customize_Media_Control' );
|
||||
$this->register_control_type( 'WP_Customize_Upload_Control' );
|
||||
|
||||
@@ -214,7 +214,7 @@ class WP_Customize_Panel {
|
||||
* @return array The array to be exported to the client as JSON.
|
||||
*/
|
||||
public function json() {
|
||||
$array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) );
|
||||
$array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) );
|
||||
$array['content'] = $this->get_content();
|
||||
$array['active'] = $this->active();
|
||||
$array['instanceNumber'] = $this->instance_number;
|
||||
@@ -289,48 +289,92 @@ class WP_Customize_Panel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the panel container, and then its contents.
|
||||
* Render the panel container, and then its contents (via `this->render_content()`) in a subclass.
|
||||
*
|
||||
* Panel containers are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function render() {
|
||||
$classes = 'accordion-section control-section control-panel control-panel-' . $this->type;
|
||||
protected function render() {}
|
||||
|
||||
/**
|
||||
* Render the panel UI in a subclass.
|
||||
*
|
||||
* Panel contents are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}.
|
||||
*
|
||||
* @since 4.1.0
|
||||
* @access protected
|
||||
*/
|
||||
protected function render_content() {}
|
||||
|
||||
/**
|
||||
* Render the panel's JS templates.
|
||||
*
|
||||
* This function is only run for panel types that have been registered with
|
||||
* {@see WP_Customize_Manager::register_panel_type()}.
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function print_template() {
|
||||
?>
|
||||
<li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
|
||||
<script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr( $this->type ); ?>-content">
|
||||
<?php $this->content_template(); ?>
|
||||
</script>
|
||||
<script type="text/html" id="tmpl-customize-panel-<?php echo esc_attr( $this->type ); ?>">
|
||||
<?php $this->render_template(); ?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* An Underscore (JS) template for rendering this panel's container.
|
||||
*
|
||||
* Class variables for this panel class are available in the `data` JS object;
|
||||
* export custom variables by overriding {@see WP_Customize_Panel::json()}.
|
||||
*
|
||||
* @see WP_Customize_Panel::print_template()
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
protected function render_template() {
|
||||
?>
|
||||
<li id="accordion-panel-{{ data.id }}" class="accordion-section control-section control-panel control-panel-{{ data.type }}">
|
||||
<h3 class="accordion-section-title" tabindex="0">
|
||||
<?php echo esc_html( $this->title ); ?>
|
||||
{{ data.title }}
|
||||
<span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span>
|
||||
</h3>
|
||||
<ul class="accordion-sub-container control-panel-content">
|
||||
<?php $this->render_content(); ?>
|
||||
</ul>
|
||||
<ul class="accordion-sub-container control-panel-content"></ul>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the sections that have been added to the panel.
|
||||
* An Underscore (JS) template for this panel's content (but not its container).
|
||||
*
|
||||
* @since 4.1.0
|
||||
* @access protected
|
||||
* Class variables for this panel class are available in the `data` JS object;
|
||||
* export custom variables by overriding {@see WP_Customize_Panel::json()}.
|
||||
*
|
||||
* @see WP_Customize_Panel::print_template()
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
protected function render_content() {
|
||||
protected function content_template() {
|
||||
?>
|
||||
<li class="panel-meta customize-info accordion-section<?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>">
|
||||
<li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>">
|
||||
<button class="customize-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></button>
|
||||
<div class="accordion-section-title">
|
||||
<span class="preview-notice"><?php
|
||||
/* translators: %s is the site/panel title in the Customizer */
|
||||
echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' );
|
||||
echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' );
|
||||
?></span>
|
||||
<button class="customize-help-toggle dashicons dashicons-editor-help" tabindex="0" aria-expanded="false"><span class="screen-reader-text"><?php _e( 'Help' ); ?></span></button>
|
||||
</div>
|
||||
<?php if ( ! empty( $this->description ) ) : ?>
|
||||
<# if ( data.description ) { #>
|
||||
<div class="description customize-panel-description">
|
||||
<?php echo $this->description; ?>
|
||||
{{{ data.description }}}
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<# } #>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -223,10 +223,18 @@ class WP_Customize_Section {
|
||||
* @return array The array to be exported to the client as JSON.
|
||||
*/
|
||||
public function json() {
|
||||
$array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) );
|
||||
$array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'panel', 'type' ) );
|
||||
$array['content'] = $this->get_content();
|
||||
$array['active'] = $this->active();
|
||||
$array['instanceNumber'] = $this->instance_number;
|
||||
|
||||
if ( $this->panel ) {
|
||||
/* translators: ▸ is the unicode right-pointing triangle, and %s is the section title in the Customizer */
|
||||
$array['customizeAction'] = sprintf( __( 'Customizing ▸ %s' ), esc_html( $this->manager->get_panel( $this->panel )->title ) );
|
||||
} else {
|
||||
$array['customizeAction'] = __( 'Customizing' );
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -251,7 +259,7 @@ class WP_Customize_Section {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the section's content template for insertion into the Customizer pane.
|
||||
* Get the section's content for insertion into the Customizer pane.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
@@ -297,16 +305,45 @@ class WP_Customize_Section {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the section, and the controls that have been added to it.
|
||||
* Render the section UI in a subclass.
|
||||
*
|
||||
* Sections are now rendered in JS by default, see {@see WP_Customize_Section::print_template()}.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
protected function render() {
|
||||
$classes = 'accordion-section control-section control-section-' . $this->type;
|
||||
protected function render() {}
|
||||
|
||||
/**
|
||||
* Render the section's JS template.
|
||||
*
|
||||
* This function is only run for section types that have been registered with
|
||||
* {@see WP_Customize_Manager::register_section_type()}.
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function print_template() {
|
||||
?>
|
||||
<script type="text/html" id="tmpl-customize-section-<?php echo $this->type; ?>">
|
||||
<?php $this->render_template(); ?>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* An Underscore (JS) template for rendering this section.
|
||||
*
|
||||
* Class variables for this section class are available in the `data` JS object;
|
||||
* export custom variables by overriding {@see WP_Customize_Section::json()}.
|
||||
*
|
||||
* @see WP_Customize_Section::print_template()
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
protected function render_template() {
|
||||
?>
|
||||
<li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
|
||||
<li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}">
|
||||
<h3 class="accordion-section-title" tabindex="0">
|
||||
<?php echo esc_html( $this->title ); ?>
|
||||
{{ data.title }}
|
||||
<span class="screen-reader-text"><?php _e( 'Press return or enter to open' ); ?></span>
|
||||
</h3>
|
||||
<ul class="accordion-section-content">
|
||||
@@ -316,20 +353,15 @@ class WP_Customize_Section {
|
||||
<span class="screen-reader-text"><?php _e( 'Back' ); ?></span>
|
||||
</button>
|
||||
<h3>
|
||||
<span class="customize-action"><?php
|
||||
if ( $this->panel ) {
|
||||
/* translators: ▸ is the unicode right-pointing triangle, and %s is the section title in the Customizer */
|
||||
echo sprintf( __( 'Customizing ▸ %s' ), esc_html( $this->manager->get_panel( $this->panel )->title ) );
|
||||
} else {
|
||||
_e( 'Customizing' );
|
||||
}
|
||||
?></span>
|
||||
<?php echo esc_html( $this->title ); ?>
|
||||
<span class="customize-action">
|
||||
{{{ data.customizeAction }}}
|
||||
</span>
|
||||
{{ data.title }}
|
||||
</h3>
|
||||
</div>
|
||||
<?php if ( ! empty( $this->description ) ) : ?>
|
||||
<p class="description customize-section-description"><?php echo $this->description; ?></p>
|
||||
<?php endif; ?>
|
||||
<# if ( data.description ) { #>
|
||||
<p class="description customize-section-description">{{{ data.description }}}</p>
|
||||
<# } #>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-alpha-32657';
|
||||
$wp_version = '4.3-alpha-32658';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user