Make WordPress Core

Ticket #30738: 30738.diff

File 30738.diff, 9.0 KB (added by obenland, 8 years ago)
  • src/wp-admin/js/customize-controls.js

     
    14881488                        var template,
    14891489                                control = this;
    14901490
     1491                        // If there's already content, bail.
     1492                        if ( control.container.is( ':empty' ) ) {
     1493                                return;
     1494                        }
    14911495                        // Replace the container element's content with the control.
    14921496                        if ( 0 !== $( '#tmpl-' + control.templateSelector ).length ) {
    14931497                                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 ) );
    14971504                        }
    14981505                }
    14991506        });
  • src/wp-includes/class-wp-customize-control.php

     
    257257                $this->json['label'] = $this->label;
    258258                $this->json['description'] = $this->description;
    259259                $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();
    260264        }
    261265
    262266        /**
     
    388392         * @access public
    389393         */
    390394        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 = '';
    391407                foreach( $this->input_attrs as $attr => $value ) {
    392                         echo $attr . '="' . esc_attr( $value ) . '" ';
     408                        $attrs .= $attr . '="' . esc_attr( $value ) . '" ';
    393409                }
     410                return $attrs;
    394411        }
    395412
    396413        /**
     
    404421         * Control content can alternately be rendered in JS. See {@see WP_Customize_Control::print_template()}.
    405422         *
    406423         * @since 3.4.0
     424         * @since 4.3.0 Most core control types are rendered with a content template instead.
    407425         */
    408426        protected function render_content() {
    409427                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                                 <?php
    420                                 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                                         <?php
    441                                 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                                                 <?php
    458                                                 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                                 <?php
    464                                 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                                 <?php
    477                                 break;
    478428                        case 'dropdown-pages':
    479429                                $dropdown = wp_dropdown_pages(
    480430                                        array(
     
    495445                                        $dropdown
    496446                                );
    497447                                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                                 <?php
    510                                 break;
    511448                }
    512449        }
    513450
     
    518455         * {@see WP_Customize_Manager::register_control_type()}.
    519456         *
    520457         * 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
    522459         *
    523460         * @since 4.1.0
    524461         */
     
    539476         * @see WP_Customize_Control::print_template()
    540477         *
    541478         * @since 4.1.0
     479         * @since 4.3.0 Core base control class uses JS templates by default.
    542480         */
    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                                        <# } #>
    544542
     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        }
    545561}
    546562
    547563/**
  • src/wp-includes/class-wp-customize-manager.php

     
    11571157                        $control = new $control_type( $this, 'temp', array() );
    11581158                        $control->print_template();
    11591159                }
     1160                // Base control, for built-in & fallback types.
     1161                $control = new WP_Customize_Control( $this, 'temp', array( 'type' => 'default' ) );
     1162                $control->print_template();
    11601163        }
    11611164
    11621165        /**