Ticket #30738: 30738.diff
File 30738.diff, 9.0 KB (added by , 8 years ago) |
---|
-
src/wp-admin/js/customize-controls.js
1488 1488 var template, 1489 1489 control = this; 1490 1490 1491 // If there's already content, bail. 1492 if ( control.container.is( ':empty' ) ) { 1493 return; 1494 } 1491 1495 // Replace the container element's content with the control. 1492 1496 if ( 0 !== $( '#tmpl-' + control.templateSelector ).length ) { 1493 1497 template = wp.template( control.templateSelector ); 1494 if ( template && control.container ) { 1495 control.container.html( template( control.params ) ); 1496 } 1498 } else { 1499 template = wp.template( 'customize-control-default-content' ); 1500 } 1501 1502 if ( template && control.container ) { 1503 control.container.html( template( control.params ) ); 1497 1504 } 1498 1505 } 1499 1506 }); -
src/wp-includes/class-wp-customize-control.php
257 257 $this->json['label'] = $this->label; 258 258 $this->json['description'] = $this->description; 259 259 $this->json['instanceNumber'] = $this->instance_number; 260 $this->json['value'] = $this->value(); 261 $this->json['link'] = $this->get_link(); 262 $this->json['choices'] = $this->choices; 263 $this->json['inputAttrs'] = $this->get_input_attrs(); 260 264 } 261 265 262 266 /** … … 388 392 * @access public 389 393 */ 390 394 public function input_attrs() { 395 echo $this->get_input_attrs(); 396 } 397 398 /** 399 * Return html for the custom attributes for the control's input element. 400 * 401 * @since 4.3.0 402 * @access public 403 * @return string Input attributes html. 404 */ 405 public function get_input_attrs() { 406 $attrs = ''; 391 407 foreach( $this->input_attrs as $attr => $value ) { 392 echo$attr . '="' . esc_attr( $value ) . '" ';408 $attrs .= $attr . '="' . esc_attr( $value ) . '" '; 393 409 } 410 return $attrs; 394 411 } 395 412 396 413 /** … … 404 421 * Control content can alternately be rendered in JS. See {@see WP_Customize_Control::print_template()}. 405 422 * 406 423 * @since 3.4.0 424 * @since 4.3.0 Most core control types are rendered with a content template instead. 407 425 */ 408 426 protected function render_content() { 409 427 switch( $this->type ) { 410 case 'checkbox':411 ?>412 <label>413 <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />414 <?php echo esc_html( $this->label ); ?>415 <?php if ( ! empty( $this->description ) ) : ?>416 <span class="description customize-control-description"><?php echo $this->description; ?></span>417 <?php endif; ?>418 </label>419 <?php420 break;421 case 'radio':422 if ( empty( $this->choices ) )423 return;424 425 $name = '_customize-radio-' . $this->id;426 427 if ( ! empty( $this->label ) ) : ?>428 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>429 <?php endif;430 if ( ! empty( $this->description ) ) : ?>431 <span class="description customize-control-description"><?php echo $this->description ; ?></span>432 <?php endif;433 434 foreach ( $this->choices as $value => $label ) :435 ?>436 <label>437 <input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> />438 <?php echo esc_html( $label ); ?><br/>439 </label>440 <?php441 endforeach;442 break;443 case 'select':444 if ( empty( $this->choices ) )445 return;446 447 ?>448 <label>449 <?php if ( ! empty( $this->label ) ) : ?>450 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>451 <?php endif;452 if ( ! empty( $this->description ) ) : ?>453 <span class="description customize-control-description"><?php echo $this->description; ?></span>454 <?php endif; ?>455 456 <select <?php $this->link(); ?>>457 <?php458 foreach ( $this->choices as $value => $label )459 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';460 ?>461 </select>462 </label>463 <?php464 break;465 case 'textarea':466 ?>467 <label>468 <?php if ( ! empty( $this->label ) ) : ?>469 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>470 <?php endif;471 if ( ! empty( $this->description ) ) : ?>472 <span class="description customize-control-description"><?php echo $this->description; ?></span>473 <?php endif; ?>474 <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>475 </label>476 <?php477 break;478 428 case 'dropdown-pages': 479 429 $dropdown = wp_dropdown_pages( 480 430 array( … … 495 445 $dropdown 496 446 ); 497 447 break; 498 default:499 ?>500 <label>501 <?php if ( ! empty( $this->label ) ) : ?>502 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>503 <?php endif;504 if ( ! empty( $this->description ) ) : ?>505 <span class="description customize-control-description"><?php echo $this->description; ?></span>506 <?php endif; ?>507 <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />508 </label>509 <?php510 break;511 448 } 512 449 } 513 450 … … 518 455 * {@see WP_Customize_Manager::register_control_type()}. 519 456 * 520 457 * In the future, this will also print the template for the control's container 521 * element and be override-able. 458 * element and be override-able. @link https://core.trac.wordpress.org/ticket/30741 522 459 * 523 460 * @since 4.1.0 524 461 */ … … 539 476 * @see WP_Customize_Control::print_template() 540 477 * 541 478 * @since 4.1.0 479 * @since 4.3.0 Core base control class uses JS templates by default. 542 480 */ 543 protected function content_template() {} 481 protected function content_template() { 482 ?> 483 <# switch ( data.type ) { 484 case 'checkbox': #> 485 <label> 486 <input type="checkbox" value="{{ data.value }}" {{{ data.link }}} <# if ( data.value ) { #> checked="checked" <# } #> /> 487 {{ data.label }} 488 <# if ( data.description ) { #> 489 <span class="description customize-control-description">{{ data.description }}</span> 490 <# } #> 491 </label> 492 <# 493 break; 494 case 'radio': 495 if ( ! data.choices ) { 496 return; 497 } 498 499 var name = '_customize-radio-' + data.id; 500 501 if ( data.label ) { #> 502 <span class="customize-control-title">{{ data.label }}</span> 503 <# } if ( data.description ) { #> 504 <span class="description customize-control-description">{{{ data.description }}}</span> 505 <# } 506 507 for ( key in data.choices ) { #> 508 <label> 509 <input type="radio" value="{{ key }}" name="{{ name }}" {{{ data.link }}} <# if ( data.choices[key] === data.value ) { #> checked="checked" <# } #> /> 510 {{ data.label }}<br/> 511 </label> 512 <# } 513 break; 514 case 'select': 515 if ( ! data.choices ) { 516 return; 517 } 518 #> 519 <label> 520 <# if ( data.label ) { #> 521 <span class="customize-control-title">{{ data.label }}</span> 522 <# } if ( data.description ) { #> 523 <span class="description customize-control-description">{{{ data.description }}}</span> 524 <# } #> 525 526 <select {{{ data.link }}}> 527 <# for ( key in data.choices ) { #> 528 <option value="{{ key }}" <# if ( data.choices[key] === data.value ) { #>selected="selected" <# } #>>{{ data.label }}</option> 529 <# } #> 530 </select> 531 </label> 532 <# 533 break; 534 case 'textarea': 535 #> 536 <label> 537 <# if ( data.label ) { #> 538 <span class="customize-control-title">{{ data.label }}</span> 539 <# } if ( data.description ) { #> 540 <span class="description customize-control-description">{{{ data.description }}}</span> 541 <# } #> 544 542 543 <textarea rows="5" {{{ data.link }}}>{{ data.value }}</textarea> 544 </label> 545 <# 546 break; 547 default: 548 #> 549 <label> 550 <# if ( data.label ) { #> 551 <span class="customize-control-title">{{ data.label }}</span> 552 <# } if ( data.description ) { #> 553 <span class="description customize-control-description">{{{ data.description }}}</span> 554 <# } #> 555 556 <input type="{{ data.type }}" {{{ data.inputAttrs }}} value="{{ data.value }}" {{{ data.link }}} /> 557 </label> 558 <# } #> 559 <?php 560 } 545 561 } 546 562 547 563 /** -
src/wp-includes/class-wp-customize-manager.php
1157 1157 $control = new $control_type( $this, 'temp', array() ); 1158 1158 $control->print_template(); 1159 1159 } 1160 // Base control, for built-in & fallback types. 1161 $control = new WP_Customize_Control( $this, 'temp', array( 'type' => 'default' ) ); 1162 $control->print_template(); 1160 1163 } 1161 1164 1162 1165 /**