Customize: Move control's fallback selection of default content template to renderContent method to align with sections and panels.

* Only use default control content template when a more specific template doesn't exist.
* Remove extraneous whitespace from being output in `WP_Customize_Control::render()` method.
* Move Custom Header template printing to `customize_controls_print_footer_scripts` action.

See #30738.

Built from https://develop.svn.wordpress.org/trunk@41935


git-svn-id: http://core.svn.wordpress.org/trunk@41769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-10-19 03:04:49 +00:00
parent c81acd7cef
commit f8d16c8aed
5 changed files with 40 additions and 34 deletions

View File

@ -3362,7 +3362,7 @@
}, },
initialize: function( id, options ) { initialize: function( id, options ) {
var control = this, deferredSettingIds = [], settings, gatherSettings, standardTypes; var control = this, deferredSettingIds = [], settings, gatherSettings;
control.params = _.extend( {}, control.defaults ); control.params = _.extend( {}, control.defaults );
@ -3401,30 +3401,8 @@
control.container = $( control.selector ); // Likely dead, per above. See #28709. control.container = $( control.selector ); // Likely dead, per above. See #28709.
} }
standardTypes = [
'button',
'checkbox',
'date',
'datetime-local',
'email',
'month',
'number',
'password',
'radio',
'range',
'search',
'select',
'tel',
'time',
'text',
'textarea',
'week',
'url'
];
if ( control.params.templateId ) { if ( control.params.templateId ) {
control.templateSelector = control.params.templateId; control.templateSelector = control.params.templateId;
} else if ( _.contains( standardTypes, control.params.type ) && control.container.is( ':empty' ) ) {
control.templateSelector = 'customize-control-default-content';
} else { } else {
control.templateSelector = 'customize-control-' + control.params.type + '-content'; control.templateSelector = 'customize-control-' + control.params.type + '-content';
} }
@ -3886,12 +3864,39 @@
* @since 4.1.0 * @since 4.1.0
*/ */
renderContent: function () { renderContent: function () {
var template, var control = this, template, standardTypes, templateId;
control = this;
standardTypes = [
'button',
'checkbox',
'date',
'datetime-local',
'email',
'month',
'number',
'password',
'radio',
'range',
'search',
'select',
'tel',
'time',
'text',
'textarea',
'week',
'url'
];
templateId = control.templateSelector;
// Use default content template when a standard HTML type is used and there isn't a more specific template existing.
if ( templateId === 'customize-control-' + control.params.type + '-content' && _.contains( standardTypes, control.params.type ) && ! document.getElementById( 'tmpl-' + templateId ) ) {
templateId = 'customize-control-default-content';
}
// Replace the container element's content with the control. // Replace the container element's content with the control.
if ( 0 !== $( '#tmpl-' + control.templateSelector ).length ) { if ( document.getElementById( 'tmpl-' + templateId ) ) {
template = wp.template( control.templateSelector ); template = wp.template( templateId );
if ( template && control.container ) { if ( template && control.container ) {
control.container.html( template( control.params ) ); control.container.html( template( control.params ) );
} }

File diff suppressed because one or more lines are too long

View File

@ -421,9 +421,9 @@ class WP_Customize_Control {
$id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id ); $id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id );
$class = 'customize-control customize-control-' . $this->type; $class = 'customize-control customize-control-' . $this->type;
?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>"> printf( '<li id="%s" class="%s">', esc_attr( $id ), esc_attr( $class ) );
<?php $this->render_content(); ?> $this->render_content();
</li><?php echo '</li>';
} }
/** /**

View File

@ -77,6 +77,8 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
return; return;
} }
add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_header_image_template' ) );
// Process default headers and uploaded headers. // Process default headers and uploaded headers.
$custom_image_header->process_default_headers(); $custom_image_header->process_default_headers();
$this->default_headers = $custom_image_header->get_default_header_images(); $this->default_headers = $custom_image_header->get_default_header_images();
@ -157,7 +159,6 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
/** /**
*/ */
public function render_content() { public function render_content() {
$this->print_header_image_template();
$visibility = $this->get_current_image_src() ? '' : ' style="display:none" '; $visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
$width = absint( get_theme_support( 'custom-header', 'width' ) ); $width = absint( get_theme_support( 'custom-header', 'width' ) );
$height = absint( get_theme_support( 'custom-header', 'height' ) ); $height = absint( get_theme_support( 'custom-header', 'height' ) );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-beta2-41934'; $wp_version = '4.9-beta2-41935';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.