Make WordPress Core

Changeset 28930


Ignore:
Timestamp:
06/30/2014 07:47:56 PM (12 years ago)
Author:
ocean90
Message:

Customizer: Support textarea and commonly-used input types as control type in WP_Customize_Control.
Add input_attrs property to support custom input attributes.

(Demo plugin attached to ticket.)

props celloexpressions.
fixes #28477.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/customize-controls.css

    r28927 r28930  
    288288
    289289.customize-control select,
    290 .customize-control input[type="text"],
    291290.customize-control input[type="radio"],
    292291.customize-control input[type="checkbox"] {
     
    294293}
    295294
    296 .customize-control input[type="text"] {
     295.customize-control input[type="text"],
     296.customize-control input[type="password"],
     297.customize-control input[type="email"],
     298.customize-control input[type="number"],
     299.customize-control input[type="search"],
     300.customize-control input[type="tel"],
     301.customize-control input[type="url"] {
    297302        width: 98%;
    298303        line-height: 18px;
    299304        margin: 0;
     305}
     306
     307.customize-control-textarea textarea {
     308        width: 100%;
     309        resize: vertical;
    300310}
    301311
  • trunk/src/wp-includes/class-wp-customize-control.php

    r28927 r28930  
    6767         */
    6868        public $choices = array();
     69
     70        /**
     71         * @access public
     72         * @var array
     73         */
     74        public $input_attrs = array();
    6975
    7076        /**
     
    251257        }
    252258
     259        /**
     260         * Render the custom attributes for the control's input element.
     261         *
     262         * @since 4.0.0
     263         */
     264        public function input_attrs() {
     265                foreach( $this->input_attrs as $attr => $value ) {
     266                        echo $attr . '="' . esc_attr( $value ) . '" ';
     267                }
     268        }
     269
    253270        /**
    254271         * Render the control's content.
     
    256273         * Allows the content to be overriden without having to rewrite the wrapper in $this->render().
    257274         *
    258          * Supports basic input types `text`, `checkbox`, `radio`, `select` and `dropdown-pages`.
     275         * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
     276         * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
    259277         *
    260278         * @since 3.4.0
     
    262280        protected function render_content() {
    263281                switch( $this->type ) {
    264                         case 'text':
    265                                 ?>
    266                                 <label>
    267                                         <?php if ( ! empty( $this->label ) ) : ?>
    268                                                 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    269                                         <?php endif;
    270                                         if ( ! empty( $this->description ) ) : ?>
    271                                                 <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
    272                                         <?php endif; ?>
    273                                         <input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
    274                                 </label>
    275                                 <?php
    276                                 break;
    277282                        case 'checkbox':
    278283                                ?>
     
    330335                                <?php
    331336                                break;
     337                        case 'textarea':
     338                                ?>
     339                                <label>
     340                                        <?php if ( ! empty( $this->label ) ) : ?>
     341                                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
     342                                        <?php endif;
     343                                        if ( ! empty( $this->description ) ) : ?>
     344                                                <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
     345                                        <?php endif; ?>
     346                                        <textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
     347                                </label>
     348                                <?php
     349                                break;
    332350                        case 'dropdown-pages':
    333351                                $dropdown = wp_dropdown_pages(
     
    349367                                        $dropdown
    350368                                );
     369                                break;
     370                        default:
     371                                ?>
     372                                <label>
     373                                        <?php if ( ! empty( $this->label ) ) : ?>
     374                                                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
     375                                        <?php endif;
     376                                        if ( ! empty( $this->description ) ) : ?>
     377                                                <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
     378                                        <?php endif; ?>
     379                                        <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
     380                                </label>
     381                                <?php
    351382                                break;
    352383                }
Note: See TracChangeset for help on using the changeset viewer.