Ticket #30738: 30738.2.diff
File 30738.2.diff, 15.2 KB (added by , 6 years ago) |
---|
-
src/wp-admin/js/customize-controls.js
diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js index b483aea335..4348fee7ec 100644
216 216 setting.id = id; 217 217 setting.transport = setting.transport || 'refresh'; 218 218 setting._dirty = options.dirty || false; 219 setting['default'] = options['default']; 219 220 setting.notifications = new api.Values({ defaultConstructor: api.Notification }); 220 221 221 222 // Whenever the setting's value changes, refresh the preview. … … 2089 2090 defaultActiveArguments: { duration: 'fast', completeCallback: $.noop }, 2090 2091 2091 2092 initialize: function( id, options ) { 2092 var control = this, 2093 nodes, radios, settings; 2093 var control = this, settings, linkNodes; 2094 2094 2095 2095 control.params = {}; 2096 2096 $.extend( control, options || {} ); … … 2112 2112 2113 2113 control.elements = []; 2114 2114 2115 nodes = control.container.find('[data-customize-setting-link]'); 2116 radios = {}; 2115 linkNodes = function() { 2116 var nodes, radios; 2117 nodes = control.container.find( '[data-customize-setting-link]' ); 2118 radios = {}; 2117 2119 2118 nodes.each( function() {2119 var node = $( this ),2120 name;2120 nodes.each( function() { 2121 var node = $( this ), 2122 name; 2121 2123 2122 if ( node.is( ':radio' ) ) { 2123 name = node.prop( 'name' ); 2124 if ( radios[ name ] ) { 2124 if ( node.data( 'customizeSettingLinkAdded' ) ) { 2125 2125 return; 2126 2126 } 2127 2127 2128 radios[ name ] = true; 2129 node = nodes.filter( '[name="' + name + '"]' ); 2130 } 2128 if ( node.is( ':radio' ) ) { 2129 name = node.prop( 'name' ); 2130 if ( radios[ name ] ) { 2131 return; 2132 } 2133 2134 radios[ name ] = true; 2135 node = nodes.filter( '[name="' + name + '"]' ); 2136 } 2131 2137 2132 api( node.data( 'customizeSettingLink' ), function( setting ) { 2133 var element = new api.Element( node ); 2134 control.elements.push( element ); 2135 element.sync( setting ); 2136 element.set( setting() ); 2138 node.data( 'customizeSettingLinkAdded', true ); 2139 api( node.data( 'customizeSettingLink' ), function( setting ) { 2140 var element = new api.Element( node ); 2141 control.elements.push( element ); 2142 element.sync( setting ); 2143 element.set( setting() ); 2144 }); 2137 2145 }); 2138 }); 2146 }; 2147 linkNodes(); // Call early for back-compat in case no content template is being used. 2139 2148 2140 2149 control.active.bind( function ( active ) { 2141 2150 var args = control.activeArgumentsQueue.shift(); … … 2198 2207 2199 2208 // After the control is embedded on the page, invoke the "ready" method. 2200 2209 control.deferred.embedded.done( function () { 2210 linkNodes(); // Link nodes that were added via content template. 2211 2201 2212 control.setupNotifications(); 2202 2213 control.ready(); 2203 2214 }); … … 2515 2526 var template, 2516 2527 control = this; 2517 2528 2529 // If there's already content, bail. 2530 if ( control.container.is( ':empty' ) ) { 2531 return; 2532 } 2518 2533 // Replace the container element's content with the control. 2519 2534 if ( 0 !== $( '#tmpl-' + control.templateSelector ).length ) { 2520 2535 template = wp.template( control.templateSelector ); 2521 if ( template && control.container ) { 2522 control.container.html( template( control.params ) ); 2523 } 2536 } else { 2537 template = wp.template( 'customize-control-default-content' ); 2538 } 2539 2540 if ( template && control.container ) { 2541 control.container.html( template( control.params ) ); 2524 2542 } 2525 2543 }, 2526 2544 … … 4909 4927 var constructor = api.settingConstructor[ data.type ] || api.Setting, 4910 4928 setting; 4911 4929 4912 setting = new constructor( id, data.value, {4913 transport: data.transport,4914 previewer: api.previewer,4915 dirty: !! data.dirty4916 });4930 setting = new constructor( id, data.value, _.extend( 4931 {}, 4932 data, 4933 { previewer: api.previewer } 4934 ) ); 4917 4935 api.add( id, setting ); 4918 4936 }); 4919 4937 … … 5648 5666 5649 5667 // Juggle the two controls that use header_textcolor 5650 5668 api.control( 'display_header_text', function( control ) { 5651 var last = ''; 5669 control.deferred.embedded.done( function() { // @todo How to guarantee that control.elements will be populated? 5670 var last = ''; 5652 5671 5653 control.elements[0].unsync( api( 'header_textcolor' ) );5672 control.elements[0].unsync( api( 'header_textcolor' ) ); 5654 5673 5655 control.element = new api.Element( control.container.find('input') );5656 control.element.set( 'blank' !== control.setting() );5674 control.element = new api.Element( control.container.find( 'input' ) ); 5675 control.element.set( 'blank' !== control.setting() ); 5657 5676 5658 control.element.bind( function( to ) { 5659 if ( ! to ) 5660 last = api( 'header_textcolor' ).get(); 5677 control.element.bind( function( to ) { 5678 if ( ! to ) { 5679 last = api( 'header_textcolor' ).get(); 5680 } 5661 5681 5662 control.setting.set( to ? last : 'blank' );5663 });5682 control.setting.set( to ? last : 'blank' ); 5683 }); 5664 5684 5665 control.setting.bind( function( to ) { 5666 control.element.set( 'blank' !== to ); 5685 control.setting.bind( function( to ) { 5686 control.element.set( 'blank' !== to ); 5687 }); 5667 5688 }); 5668 5689 }); 5669 5690 -
src/wp-includes/class-wp-customize-control.php
diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php index b9c83c7575..8f7b4ae505 100644
class WP_Customize_Control { 316 316 $this->json['label'] = $this->label; 317 317 $this->json['description'] = $this->description; 318 318 $this->json['instanceNumber'] = $this->instance_number; 319 $this->json['value'] = $this->value(); 320 $this->json['link'] = $this->get_link(); 321 $this->json['choices'] = $this->choices; 322 $this->json['inputAttrs'] = $this->get_input_attrs(); 319 323 320 324 if ( 'dropdown-pages' === $this->type ) { 321 325 $this->json['allow_addition'] = $this->allow_addition; … … class WP_Customize_Control { 459 463 * @since 4.0.0 460 464 */ 461 465 public function input_attrs() { 462 foreach ( $this->input_attrs as $attr => $value ) { 463 echo $attr . '="' . esc_attr( $value ) . '" '; 466 echo $this->get_input_attrs(); 467 } 468 469 /** 470 * Return html for the custom attributes for the control's input element. 471 * 472 * @since 4.3.0 473 * @return string Input attributes html. 474 */ 475 public function get_input_attrs() { 476 $attrs = ''; 477 foreach( $this->input_attrs as $attr => $value ) { 478 $attrs .= $attr . '="' . esc_attr( $value ) . '" '; 464 479 } 480 return $attrs; 465 481 } 466 482 467 483 /** … … class WP_Customize_Control { 475 491 * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). 476 492 * 477 493 * @since 3.4.0 494 * @since 4.3.0 Most core control types are rendered with a content template instead. 478 495 */ 479 496 protected function render_content() { 480 497 switch( $this->type ) { 481 case 'checkbox':482 ?>483 <label>484 <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />485 <?php echo esc_html( $this->label ); ?>486 <?php if ( ! empty( $this->description ) ) : ?>487 <span class="description customize-control-description"><?php echo $this->description; ?></span>488 <?php endif; ?>489 </label>490 <?php491 break;492 case 'radio':493 if ( empty( $this->choices ) )494 return;495 496 $name = '_customize-radio-' . $this->id;497 498 if ( ! empty( $this->label ) ) : ?>499 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>500 <?php endif;501 if ( ! empty( $this->description ) ) : ?>502 <span class="description customize-control-description"><?php echo $this->description ; ?></span>503 <?php endif;504 505 foreach ( $this->choices as $value => $label ) :506 ?>507 <label>508 <input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> />509 <?php echo esc_html( $label ); ?><br/>510 </label>511 <?php512 endforeach;513 break;514 case 'select':515 if ( empty( $this->choices ) )516 return;517 518 ?>519 <label>520 <?php if ( ! empty( $this->label ) ) : ?>521 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>522 <?php endif;523 if ( ! empty( $this->description ) ) : ?>524 <span class="description customize-control-description"><?php echo $this->description; ?></span>525 <?php endif; ?>526 527 <select <?php $this->link(); ?>>528 <?php529 foreach ( $this->choices as $value => $label )530 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';531 ?>532 </select>533 </label>534 <?php535 break;536 case 'textarea':537 ?>538 <label>539 <?php if ( ! empty( $this->label ) ) : ?>540 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>541 <?php endif;542 if ( ! empty( $this->description ) ) : ?>543 <span class="description customize-control-description"><?php echo $this->description; ?></span>544 <?php endif; ?>545 <textarea rows="5" <?php $this->input_attrs(); ?> <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>546 </label>547 <?php548 break;549 498 case 'dropdown-pages': 550 499 ?> 551 500 <label> … … class WP_Customize_Control { 609 558 </div> 610 559 <?php endif; 611 560 break; 612 default:613 ?>614 <label>615 <?php if ( ! empty( $this->label ) ) : ?>616 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>617 <?php endif;618 if ( ! empty( $this->description ) ) : ?>619 <span class="description customize-control-description"><?php echo $this->description; ?></span>620 <?php endif; ?>621 <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />622 </label>623 <?php624 break;625 561 } 626 562 } 627 563 … … class WP_Customize_Control { 632 568 * WP_Customize_Manager::register_control_type(). 633 569 * 634 570 * In the future, this will also print the template for the control's container 635 * element and be override-able. 571 * element and be override-able. @link https://core.trac.wordpress.org/ticket/30741 636 572 * 637 573 * @since 4.1.0 638 574 */ … … class WP_Customize_Control { 653 589 * @see WP_Customize_Control::print_template() 654 590 * 655 591 * @since 4.1.0 592 * @since 4.3.0 Core base control class uses JS templates by default. 656 593 */ 657 protected function content_template() {} 594 protected function content_template() { 595 ?> 596 <# switch ( data.type ) { 597 case 'checkbox': #> 598 <label> 599 <input type="checkbox" value="{{ data.value }}" {{{ data.link }}} <# if ( data.value ) { #> checked="checked" <# } #> /> 600 {{ data.label }} 601 <# if ( data.description ) { #> 602 <span class="description customize-control-description">{{ data.description }}</span> 603 <# } #> 604 </label> 605 <# 606 break; 607 case 'radio': 608 if ( ! data.choices ) { 609 return; 610 } 611 612 var name = '_customize-radio-' + data.id; 658 613 614 if ( data.label ) { #> 615 <span class="customize-control-title">{{ data.label }}</span> 616 <# } if ( data.description ) { #> 617 <span class="description customize-control-description">{{{ data.description }}}</span> 618 <# } 619 620 for ( key in data.choices ) { #> 621 <label> 622 <input type="radio" value="{{ key }}" name="{{ name }}" {{{ data.link }}} <# if ( data.choices[key] === data.value ) { #> checked="checked" <# } #> /> 623 {{ data.label }}<br/> 624 </label> 625 <# } 626 break; 627 case 'select': 628 if ( ! data.choices ) { 629 return; 630 } 631 #> 632 <label> 633 <# if ( data.label ) { #> 634 <span class="customize-control-title">{{ data.label }}</span> 635 <# } if ( data.description ) { #> 636 <span class="description customize-control-description">{{{ data.description }}}</span> 637 <# } #> 638 639 <select {{{ data.link }}}> 640 <# for ( key in data.choices ) { #> 641 <option value="{{ key }}" <# if ( data.choices[key] === data.value ) { #>selected="selected" <# } #>>{{ data.label }}</option> 642 <# } #> 643 </select> 644 </label> 645 <# 646 break; 647 case 'textarea': 648 #> 649 <label> 650 <# if ( data.label ) { #> 651 <span class="customize-control-title">{{ data.label }}</span> 652 <# } if ( data.description ) { #> 653 <span class="description customize-control-description">{{{ data.description }}}</span> 654 <# } #> 655 656 <textarea rows="5" {{{ data.inputAttrs }}} {{{ data.link }}}>{{ data.value }}</textarea> 657 </label> 658 <# 659 break; 660 default: 661 #> 662 <label> 663 <# if ( data.label ) { #> 664 <span class="customize-control-title">{{ data.label }}</span> 665 <# } if ( data.description ) { #> 666 <span class="description customize-control-description">{{{ data.description }}}</span> 667 <# } #> 668 669 <input type="{{ data.type }}" {{{ data.inputAttrs }}} value="{{ data.value }}" {{{ data.link }}} /> 670 </label> 671 <# } #> 672 <?php 673 } 659 674 } 660 675 661 676 /** -
src/wp-includes/class-wp-customize-manager.php
diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php index 5e66a1aa75..74b15ec969 100644
final class WP_Customize_Manager { 3200 3200 $control->print_template(); 3201 3201 } 3202 3202 3203 // Base control, for built-in & fallback types. 3204 $control = new WP_Customize_Control( $this, 'temp', array( 'type' => 'default' ) ); 3205 $control->print_template(); 3206 3207 $header_image_control = $this->get_control( 'header_image' ); 3208 if ( $header_image_control instanceof WP_Customize_Header_Image_Control ) { 3209 $header_image_control->print_header_image_template(); 3210 } 3211 3203 3212 ?> 3204 3213 <script type="text/html" id="tmpl-customize-notification"> 3205 3214 <li class="notice notice-{{ data.type || 'info' }} {{ data.alt ? 'notice-alt' : '' }} {{ data.dismissible ? 'is-dismissible' : '' }}" data-code="{{ data.code }}" data-type="{{ data.type }}"> -
src/wp-includes/class-wp-customize-setting.php
diff --git src/wp-includes/class-wp-customize-setting.php src/wp-includes/class-wp-customize-setting.php index 601990f532..a5bddab000 100644
class WP_Customize_Setting { 805 805 'transport' => $this->transport, 806 806 'dirty' => $this->dirty, 807 807 'type' => $this->type, 808 'default' => $this->default, 808 809 ); 809 810 } 810 811 -
src/wp-includes/customize/class-wp-customize-header-image-control.php
diff --git src/wp-includes/customize/class-wp-customize-header-image-control.php src/wp-includes/customize/class-wp-customize-header-image-control.php index 8bf93e7df1..eab94c5d8d 100644
class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { 84 84 } 85 85 86 86 /** 87 * @todo This should go in the content_template() method. 87 88 */ 88 89 public function print_header_image_template() { 89 90 ?> … … class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { 157 158 /** 158 159 */ 159 160 public function render_content() { 160 $this->print_header_image_template();161 161 $visibility = $this->get_current_image_src() ? '' : ' style="display:none" '; 162 162 $width = absint( get_theme_support( 'custom-header', 'width' ) ); 163 163 $height = absint( get_theme_support( 'custom-header', 'height' ) );