From 1c04006909054cc458429ea1268e5aa8ee33a8f5 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 19 Oct 2017 03:03:19 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@41935 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/customize-controls.js | 59 ++++++++++--------- .../class-wp-customize-control.php | 6 +- ...lass-wp-customize-header-image-control.php | 3 +- tests/phpunit/tests/customize/widgets.php | 2 +- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 4beee3cca9..541a46731c 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -3362,7 +3362,7 @@ }, initialize: function( id, options ) { - var control = this, deferredSettingIds = [], settings, gatherSettings, standardTypes; + var control = this, deferredSettingIds = [], settings, gatherSettings; control.params = _.extend( {}, control.defaults ); @@ -3401,30 +3401,8 @@ 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 ) { control.templateSelector = control.params.templateId; - } else if ( _.contains( standardTypes, control.params.type ) && control.container.is( ':empty' ) ) { - control.templateSelector = 'customize-control-default-content'; } else { control.templateSelector = 'customize-control-' + control.params.type + '-content'; } @@ -3886,12 +3864,39 @@ * @since 4.1.0 */ renderContent: function () { - var template, - control = this; + var control = this, template, standardTypes, templateId; + + 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. - if ( 0 !== $( '#tmpl-' + control.templateSelector ).length ) { - template = wp.template( control.templateSelector ); + if ( document.getElementById( 'tmpl-' + templateId ) ) { + template = wp.template( templateId ); if ( template && control.container ) { control.container.html( template( control.params ) ); } diff --git a/src/wp-includes/class-wp-customize-control.php b/src/wp-includes/class-wp-customize-control.php index 61421b7a59..848608139d 100644 --- a/src/wp-includes/class-wp-customize-control.php +++ b/src/wp-includes/class-wp-customize-control.php @@ -421,9 +421,9 @@ class WP_Customize_Control { $id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id ); $class = 'customize-control customize-control-' . $this->type; - ?>
  • - render_content(); ?> -
  • ', esc_attr( $id ), esc_attr( $class ) ); + $this->render_content(); + echo ''; } /** diff --git a/src/wp-includes/customize/class-wp-customize-header-image-control.php b/src/wp-includes/customize/class-wp-customize-header-image-control.php index 75cb19503d..edc8f891b2 100644 --- a/src/wp-includes/customize/class-wp-customize-header-image-control.php +++ b/src/wp-includes/customize/class-wp-customize-header-image-control.php @@ -77,6 +77,8 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { return; } + add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_header_image_template' ) ); + // Process default headers and uploaded headers. $custom_image_header->process_default_headers(); $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() { - $this->print_header_image_template(); $visibility = $this->get_current_image_src() ? '' : ' style="display:none" '; $width = absint( get_theme_support( 'custom-header', 'width' ) ); $height = absint( get_theme_support( 'custom-header', 'height' ) ); diff --git a/tests/phpunit/tests/customize/widgets.php b/tests/phpunit/tests/customize/widgets.php index 0e0b786f22..5a70815e4e 100644 --- a/tests/phpunit/tests/customize/widgets.php +++ b/tests/phpunit/tests/customize/widgets.php @@ -421,7 +421,7 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase { $params = $control->json(); $this->assertEquals( 'widget_form', $params['type'] ); - $this->assertRegExp( '#^]+>\s+$#', $params['content'] ); + $this->assertRegExp( '#^]+>\s*$#', $params['content'] ); $this->assertRegExp( '#^]*class=\'widget\'[^>]*#s', $params['widget_control'] ); $this->assertContains( '
    ', $params['widget_control'] ); $this->assertNotContains( '