Make WordPress Core

Changeset 20295


Ignore:
Timestamp:
03/28/2012 04:14:09 AM (14 years ago)
Author:
koopersmith
Message:

Create WP_Customize_Control to separate the process of rendering a control from fetching, previewing, and saving its values. see #19910.

Many-to-many mapping between settings and controls.

  • Settings and controls have been separated in both the PHP (WP_Customize_Setting, WP_Customize_Control) and the JS (wp.customize.Setting, wp.customize.Control).
  • While most settings are tied to a single control, some require multiple controls. The 'header_textcolor' control is a good example: to hide the header text, header_textcolor is set to 'blank'.

Add 'Display Header Text' control.

A handful of miscellaneous bugfixes along the way.

Notes:

  • Controls should be separated out a bit more; juggling type-specific arguments in the switch statement is rather inelegant.
  • Page dropdowns are currently inactive and need to be re-linked.
Location:
trunk/wp-includes
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-customize-section.php

    r20260 r20295  
    1616        public $title          = '';
    1717        public $description    = '';
    18         public $settings;
     18        public $controls;
    1919
    2020        /**
     
    3636                $this->id = $id;
    3737
    38                 $this->settings = array(); // Users cannot customize the $settings array.
     38                $this->controls = array(); // Users cannot customize the $controls array.
    3939
    4040                return $this;
     
    8585                        <ul class="customize-section-content">
    8686                                <?php
    87                                 foreach ( $this->settings as $setting )
    88                                         $setting->maybe_render();
     87                                foreach ( $this->controls as $control )
     88                                        $control->maybe_render();
    8989                                ?>
    9090                        </ul>
  • trunk/wp-includes/class-wp-customize-setting.php

    r20290 r20295  
    1111        public $manager;
    1212        public $id;
    13         public $priority          = 10;
    14         public $section           = '';
    15         public $label             = '';
    16         public $control           = 'text';
    17         public $control_params    = array();
     13
    1814        public $type              = 'theme_mod';
    19         public $choices           = array();
    2015        public $capability        = 'edit_theme_options';
    2116        public $theme_supports    = '';
    2217        public $default           = '';
    2318        public $sanitize_callback = '';
    24         public $visibility;
    2519
    2620        protected $id_data = array();
     
    6559
    6660        /**
    67          * Enqueue setting related scripts/styles.
    68          *
    69          * @since 3.4.0
    70          */
    71         public function enqueue() {
    72                 switch( $this->control ) {
    73                         case 'color':
    74                                 wp_enqueue_script( 'farbtastic' );
    75                                 wp_enqueue_style( 'farbtastic' );
    76                                 break;
    77                         case 'upload':
    78                                 wp_enqueue_script( 'wp-plupload' );
    79                                 break;
    80                 }
    81         }
    82 
    83         /**
    8461         * Handle previewing the setting.
    8562         *
     
    276253                        return false;
    277254
    278                 $section = $this->manager->get_section( $this->section );
    279                 if ( isset( $section ) && ! $section->check_capabilities() )
    280                         return false;
    281 
    282255                return true;
    283         }
    284 
    285         /**
    286          * Check capabiliites and render the control.
    287          *
    288          * @since 3.4.0
    289          */
    290         public final function maybe_render() {
    291                 if ( ! $this->check_capabilities() )
    292                         return;
    293 
    294                 do_action( 'customize_render_setting', $this );
    295                 do_action( 'customize_render_setting_' . $this->id, $this );
    296 
    297                 $this->render();
    298         }
    299 
    300         /**
    301          * Render the control. Renders the control wrapper, then calls $this->render_content().
    302          *
    303          * @since 3.4.0
    304          */
    305         protected function render() {
    306 
    307                 $id    = 'customize-control-' . $this->id;
    308                 $class = 'customize-control customize-control-' . $this->control;
    309 
    310                 $style = '';
    311                 if ( $this->visibility ) {
    312                         if ( is_string( $this->visibility ) ) {
    313                                 $visibility_id    = $this->visibility;
    314                                 $visibility_value = true;
    315                         } else {
    316                                 $visibility_id    = $this->visibility[0];
    317                                 $visibility_value = $this->visibility[1];
    318                         }
    319                         $visibility_setting = $this->manager->get_setting( $visibility_id );
    320 
    321                         if ( $visibility_setting && $visibility_value != $visibility_setting->value() )
    322                                 $style = 'style="display:none;"';
    323                 }
    324 
    325                 ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>" <?php echo $style; ?>>
    326                         <?php $this->render_content(); ?>
    327                 </li><?php
    328         }
    329 
    330         /**
    331          * Render the control's content.
    332          *
    333          * Allows the content to be overriden without having to rewrite the wrapper.
    334          *
    335          * @since 3.4.0
    336          */
    337         protected function render_content() {
    338                 switch( $this->control ) {
    339                         case 'text':
    340                                 ?>
    341                                 <label>
    342                                         <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    343                                         <input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />
    344                                 </label>
    345                                 <?php
    346                                 break;
    347                         case 'color':
    348                                 ?>
    349                                 <label>
    350                                         <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    351                                         <div class="color-picker">
    352                                                 <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />
    353                                                 <a href="#"></a>
    354                                                 <div class="color-picker-controls">
    355                                                         <div class="farbtastic-placeholder"></div>
    356                                                         <div class="color-picker-details">
    357                                                                 <div class="color-picker-hex">
    358                                                                         <span>#</span>
    359                                                                         <input type="text" />
    360                                                                 </div>
    361                                                         </div>
    362                                                 </div>
    363                                         </div>
    364                                 </label>
    365                                 <?php
    366                                 break;
    367                         case 'checkbox':
    368                                 ?>
    369                                 <label>
    370                                         <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    371                                         <input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); checked( $this->value() ); ?> class="customize-control-content" />
    372                                 </label>
    373                                 <?php
    374                                 break;
    375                         case 'radio':
    376                                 if ( empty( $this->choices ) )
    377                                         return;
    378 
    379                                 ?>
    380                                 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    381                                 <?php
    382                                 foreach ( $this->choices as $value => $label ) :
    383                                         ?>
    384                                         <label>
    385                                                 <input type="radio" value="<?php echo esc_attr( $value ); ?>" <?php $this->name(); checked( $this->value(), $value ); ?> />
    386                                                 <?php echo esc_html( $label ); ?><br/>
    387                                         </label>
    388                                         <?php
    389                                 endforeach;
    390                                 break;
    391                         case 'select':
    392                                 if ( empty( $this->choices ) )
    393                                         return;
    394 
    395                                 ?>
    396                                 <label>
    397                                         <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    398                                         <select <?php $this->name(); ?> class="customize-control-content">
    399                                                 <?php
    400                                                 foreach ( $this->choices as $value => $label )
    401                                                         echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
    402                                                 ?>
    403                                         </select>
    404                                 </label>
    405                                 <?php
    406                                 break;
    407                         case 'upload':
    408                                 ?>
    409                                 <label>
    410                                         <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    411                                         <div>
    412                                                 <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />
    413                                                 <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
    414                                                 <a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
    415                                         </div>
    416                                 </label>
    417                                 <?php
    418                                 break;
    419                         case 'image':
    420                                 $value = $this->value();
    421 
    422                                 $image = $value;
    423                                 if ( isset( $this->control_params['get_url'] ) )
    424                                         $image = call_user_func( $this->control_params['get_url'], $image );
    425 
    426                                 ?>
    427                                 <label>
    428                                         <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    429                                         <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->name(); ?> />
    430                                         <div class="customize-image-picker">
    431                                                 <div class="thumbnail">
    432                                                         <?php if ( empty( $image ) ): ?>
    433                                                                 <img style="display:none;" />
    434                                                         <?php else: ?>
    435                                                                 <img src="<?php echo esc_url( $image ); ?>" />
    436                                                         <?php endif; ?>
    437                                                 </div>
    438                                                 <div class="actions">
    439                                                         <a href="#" class="upload"><?php _e( 'Upload New' ); ?></a>
    440                                                         <a href="#" class="change"><?php _e( 'Change Image' ); ?></a>
    441                                                         <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
    442                                                 </div>
    443                                                 <div class="library">
    444                                                         <ul>
    445                                                                 <?php foreach ( $this->control_params['tabs'] as $tab ): ?>
    446                                                                         <li data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
    447                                                                                 <?php echo esc_html( $tab[1] ); ?>
    448                                                                         </li>
    449                                                                 <?php endforeach; ?>
    450                                                         </ul>
    451                                                         <?php foreach ( $this->control_params['tabs'] as $tab ): ?>
    452                                                                 <div class="library-content" data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
    453                                                                         <?php call_user_func( $tab[2] ); ?>
    454                                                                 </div>
    455                                                         <?php endforeach; ?>
    456                                                 </div>
    457                                         </div>
    458                                 </label>
    459                                 <?php
    460                                 break;
    461                         case 'dropdown-pages':
    462                                 printf(
    463                                         '<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',
    464                                         $this->label,
    465                                         wp_dropdown_pages(
    466                                                 array(
    467                                                         'name'              => $this->get_name(),
    468                                                         'echo'              => 0,
    469                                                         'show_option_none'  => __( '&mdash; Select &mdash;' ),
    470                                                         'option_none_value' => '0',
    471                                                         'selected'          => get_option( $this->id )
    472                                                 )
    473                                         )
    474                                 );
    475                                 break;
    476                 }
    477         }
    478 
    479         /**
    480          * Retrieve the name attribute for an input.
    481          *
    482          * @since 3.4.0
    483          *
    484          * @return string The name.
    485          */
    486         public final function get_name() {
    487                 return self::name_prefix . esc_attr( $this->id );
    488         }
    489 
    490         /**
    491          * Echo the HTML name attribute for an input.
    492          *
    493          * @since 3.4.0
    494          *
    495          * @return string The HTML name attribute.
    496          */
    497         public final function name() {
    498                 echo 'name="' . $this->get_name() . '"';
    499256        }
    500257
  • trunk/wp-includes/class-wp-customize.php

    r20290 r20295  
    1515        protected $settings = array();
    1616        protected $sections = array();
     17        protected $controls = array();
    1718
    1819        /**
     
    2425                require( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
    2526                require( ABSPATH . WPINC . '/class-wp-customize-section.php' );
     27                require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    2628
    2729                add_action( 'setup_theme',  array( $this, 'setup_theme' ) );
     
    358360         * @since 3.4.0
    359361         *
    360          * @param string $id An specific ID of the setting. Can be a
     362         * @param string $id A specific ID of the setting. Can be a
    361363         *                   theme mod or option name.
    362364         * @param array $args Setting arguments.
    363365         */
    364366        public function add_setting( $id, $args = array() ) {
    365                 $setting = new WP_Customize_Setting( $this, $id, $args );
     367                if ( is_a( $id, 'WP_Customize_Setting' ) )
     368                        $setting = $id;
     369                else
     370                        $setting = new WP_Customize_Setting( $this, $id, $args );
    366371
    367372                $this->settings[ $setting->id ] = $setting;
     
    373378         * @since 3.4.0
    374379         *
    375          * @param string $id An specific ID of the setting.
     380         * @param string $id A specific ID of the setting.
    376381         * @return object The settings object.
    377382         */
     
    386391         * @since 3.4.0
    387392         *
    388          * @param string $id An specific ID of the setting.
     393         * @param string $id A specific ID of the setting.
    389394         */
    390395        public function remove_setting( $id ) {
     
    397402         * @since 3.4.0
    398403         *
    399          * @param string $id An specific ID of the section.
     404         * @param string $id A specific ID of the section.
    400405         * @param array $args Section arguments.
    401406         */
    402407        public function add_section( $id, $args = array() ) {
    403                 $section = new WP_Customize_Section( $this, $id, $args );
     408                if ( is_a( $id, 'WP_Customize_Section' ) )
     409                        $section = $id;
     410                else
     411                        $section = new WP_Customize_Section( $this, $id, $args );
    404412
    405413                $this->sections[ $section->id ] = $section;
     
    411419         * @since 3.4.0
    412420         *
    413          * @param string $id An specific ID of the section.
     421         * @param string $id A specific ID of the section.
    414422         * @return object The section object.
    415423         */
     
    424432         * @since 3.4.0
    425433         *
    426          * @param string $id An specific ID of the section.
     434         * @param string $id A specific ID of the section.
    427435         */
    428436        public function remove_section( $id ) {
    429437                unset( $this->sections[ $id ] );
     438        }
     439
     440        /**
     441         * Add a customize control.
     442         *
     443         * @since 3.4.0
     444         *
     445         * @param string $id A specific ID of the control.
     446         * @param array $args Setting arguments.
     447         */
     448        public function add_control( $id, $args = array() ) {
     449                if ( is_a( $id, 'WP_Customize_Control' ) )
     450                        $control = $id;
     451                else
     452                        $control = new WP_Customize_Control( $this, $id, $args );
     453
     454                $this->controls[ $control->id ] = $control;
     455        }
     456
     457        /**
     458         * Retrieve a customize control.
     459         *
     460         * @since 3.4.0
     461         *
     462         * @param string $id A specific ID of the control.
     463         * @return object The settings object.
     464         */
     465        public function get_control( $id ) {
     466                if ( isset( $this->controls[ $id ] ) )
     467                        return $this->controls[ $id ];
     468        }
     469
     470        /**
     471         * Remove a customize setting.
     472         *
     473         * @since 3.4.0
     474         *
     475         * @param string $id A specific ID of the control.
     476         */
     477        public function remove_control( $id ) {
     478                unset( $this->controls[ $id ] );
    430479        }
    431480
     
    453502         */
    454503        public function prepare_controls() {
    455                 // Prepare settings
     504                // Prepare controls
    456505                // Reversing makes uasort sort by time added when conflicts occur.
    457506
    458                 $this->settings = array_reverse( $this->settings );
    459                 $settings = array();
    460 
    461                 foreach ( $this->settings as $id => $setting ) {
    462                         if ( ! isset( $this->sections[ $setting->section ] ) || ! $setting->check_capabilities() )
     507                $this->controls = array_reverse( $this->controls );
     508                $controls = array();
     509
     510                foreach ( $this->controls as $id => $control ) {
     511                        if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() )
    463512                                continue;
    464513
    465                         $this->sections[ $setting->section ]->settings[] = $setting;
    466                         $settings[ $id ] = $setting;
    467                 }
    468                 $this->settings = $settings;
     514                        $this->sections[ $control->section ]->controls[] = $control;
     515                        $controls[ $id ] = $control;
     516                }
     517                $this->controls = $controls;
    469518
    470519                // Prepare sections
     
    474523
    475524                foreach ( $this->sections as $section ) {
    476                         if ( ! $section->check_capabilities() || ! $section->settings )
     525                        if ( ! $section->check_capabilities() || ! $section->controls )
    477526                                continue;
    478527
    479                         usort( $section->settings, array( $this, '_cmp_priority' ) );
     528                        usort( $section->controls, array( $this, '_cmp_priority' ) );
    480529                        $sections[] = $section;
    481530                }
     
    489538         */
    490539        public function enqueue_control_scripts() {
    491                 foreach ( $this->settings as $setting ) {
    492                         $setting->enqueue();
     540                foreach ( $this->controls as $control ) {
     541                        $control->enqueue();
    493542                }
    494543        }
     
    509558
    510559                $this->add_setting( 'header_textcolor', array(
    511                         'label'             => 'Text Color',
    512                         'section'           => 'header',
    513                         'sanitize_callback' => 'sanitize_hexcolor',
    514                         'control'           => 'color',
    515                         'theme_supports'    => array( 'custom-header', 'header-text' ),
    516                         'default'           => get_theme_support( 'custom-header', 'default-text-color' ),
    517                 ) );
    518 
    519                 /*
    520                 $this->add_setting( 'display_header', array(
    521                         'label'   => 'Display Text',
     560                        // @todo: replace with a new accept() setting method
     561                        // 'sanitize_callback' => 'sanitize_hexcolor',
     562                        'control'        => 'color',
     563                        'theme_supports' => array( 'custom-header', 'header-text' ),
     564                        'default'        => get_theme_support( 'custom-header', 'default-text-color' ),
     565                ) );
     566
     567                $this->add_control( 'display_header_text', array(
     568                        'settings' => 'header_textcolor',
     569                        'label'    => __( 'Display Header Text' ),
     570                        'section'  => 'header',
     571                        'type'     => 'checkbox',
     572                ) );
     573
     574                $this->add_control( 'header_textcolor', array(
     575                        'label'   => __( 'Text Color' ),
    522576                        'section' => 'header',
    523                         'type'    => 'radio',
    524                         'choices' => array(
    525                                 'show'  => 'Yes',
    526                                 'hide'  => 'No'
    527                         ),
    528                         // Showing header text is actually done by setting header_textcolor to 'blank'.
    529                         // @todo: Do some JS magic to make this work (since we'll be hiding the textcolor input).
    530                         'theme_mod' => false,
    531                 ) );
    532                 */
     577                        'type'    => 'color',
     578                ) );
    533579
    534580                // Input type: checkbox
    535581                // With custom value
    536582                $this->add_setting( 'header_image', array(
     583                        'default'        => get_theme_support( 'custom-header', 'default-image' ),
     584                        'theme_supports' => 'custom-header',
     585                ) );
     586
     587                $this->add_control( 'header_image', array(
    537588                        'label'          => 'Header Image',
    538589                        'section'        => 'header',
    539                         'control'        => 'image',
    540                         'default'        => get_theme_support( 'custom-header', 'default-image' ),
     590                        'type'           => 'image',
    541591                        'control_params' => array(
    542592                                'context'        => 'custom-header',
     
    560610                // With sanitize_callback
    561611                $this->add_setting( 'background_color', array(
    562                         'label'             => 'Background Color',
    563                         'section'           => 'background',
    564                         'control'           => 'color',
    565612                        'default'           => get_theme_support( 'custom-background', 'default-color' ),
    566613                        'sanitize_callback' => 'sanitize_hexcolor',
     614                        'theme_supports'    => 'custom-background',
     615                ) );
     616
     617                $this->add_control( 'background_color', array(
     618                        'label'   => __( 'Background Color' ),
     619                        'section' => 'background',
     620                        'type'    => 'color',
    567621                ) );
    568622
    569623                $this->add_setting( 'background_image', array(
    570                         'label'          => 'Background Image',
     624                        'default'        => get_theme_support( 'custom-background', 'default-image' ),
     625                        'theme_supports' => 'custom-background',
     626                ) );
     627
     628                $this->add_control( 'background_image', array(
     629                        'label'          => __( 'Background Image' ),
    571630                        'section'        => 'background',
    572                         'control'        => 'upload',
    573                         'default'        => get_theme_support( 'custom-background', 'default-image' ),
     631                        'type'           => 'upload',
    574632                        'control_params' => array(
    575633                                'context'        => 'custom-background',
     
    578636
    579637                $this->add_setting( 'background_repeat', array(
    580                         'label'      => 'Background Repeat',
     638                        'default'        => 'repeat',
     639                        'theme_supports' => 'custom-background',
     640                ) );
     641
     642                $this->add_control( 'background_repeat', array(
     643                        'label'      => __( 'Background Repeat' ),
    581644                        'section'    => 'background',
    582645                        'visibility' => 'background_image',
    583                         'control'    => 'radio',
     646                        'type'       => 'radio',
    584647                        'choices'    => array(
    585648                                'no-repeat'  => __('No Repeat'),
     
    588651                                'repeat-y'   => __('Tile Vertically'),
    589652                        ),
    590                         'default'    => 'repeat',
    591653                ) );
    592654
    593655                $this->add_setting( 'background_position_x', array(
    594                         'label'      => 'Background Position',
     656                        'default'        => 'left',
     657                        'theme_supports' => 'custom-background',
     658                ) );
     659
     660                $this->add_control( 'background_position_x', array(
     661                        'label'      => __( 'Background Position' ),
    595662                        'section'    => 'background',
    596663                        'visibility' => 'background_image',
    597                         'control'    => 'radio',
     664                        'type'       => 'radio',
    598665                        'choices'    => array(
    599666                                'left'       => __('Left'),
     
    601668                                'right'      => __('Right'),
    602669                        ),
    603                         'default'    => 'left',
    604670                ) );
    605671
    606672                $this->add_setting( 'background_attachment', array(
    607                         'label'      => 'Background Attachment',
     673                        'default'        => 'fixed',
     674                        'theme_supports' => 'custom-background',
     675                ) );
     676
     677                $this->add_control( 'background_attachment', array(
     678                        'label'      => __( 'Background Attachment' ),
    608679                        'section'    => 'background',
    609680                        'visibility' => 'background_image',
    610                         'control'    => 'radio',
     681                        'type'       => 'radio',
    611682                        'choices'    => array(
    612683                                'fixed'      => __('Fixed'),
    613684                                'scroll'     => __('Scroll'),
    614685                        ),
    615                         'default'    => 'fixed',
    616686                ) );
    617687
     
    637707                        }
    638708
    639                         $this->add_setting( "nav_menu_locations[{$location}]", array(
    640                                 'label'             => $description,
    641                                 'theme_supports'    => 'menus', // Todo: Needs also widgets -- array( 'menus', 'widgets' )
    642                                 'section'           => 'nav',
    643                                 'control'           => 'select',
    644                                 'choices'           => $choices,
     709                        $menu_setting_id = "nav_menu_locations[{$location}]";
     710
     711                        $this->add_setting( $menu_setting_id, array(
    645712                                'sanitize_callback' => 'absint',
     713                                'theme_supports'    => 'menus',
     714                        ) );
     715
     716                        $this->add_control( $menu_setting_id, array(
     717                                'label'   => $description,
     718                                'section' => 'nav',
     719                                'type'    => 'select',
     720                                'choices' => $choices,
    646721                        ) );
    647722                }
     
    661736
    662737                $this->add_setting( 'show_on_front', array(
    663                         'label'          => __( 'Front page displays' ),
     738                        'default'        => get_option( 'show_on_front' ),
     739                        'capability'     => 'manage_options',
     740                        'type'           => 'option',
    664741                //      'theme_supports' => 'static-front-page',
    665                         'section'        => 'static_front_page',
    666                         'control'        => 'radio',
    667                         'choices'        => $choices,
    668                         'default'        => get_option( 'show_on_front' ),
     742                ) );
     743
     744                $this->add_control( 'show_on_front', array(
     745                        'label'   => __( 'Front page displays' ),
     746                        'section' => 'static_front_page',
     747                        'type'    => 'radio',
     748                        'choices' => $choices,
     749                ) );
     750
     751                $this->add_setting( 'page_on_front', array(
     752                        'type'       => 'option',
     753                        'capability' => 'manage_options',
     754                //      'theme_supports' => 'static-front-page',
     755                ) );
     756
     757                $this->add_control( 'page_on_front', array(
     758                        'label'      => __( 'Front page' ),
     759                        'section'    => 'static_front_page',
     760                        'type'       => 'dropdown-pages',
     761                        'visibility' => array( 'show_on_front', 'page' ),
     762                ) );
     763
     764                $this->add_setting( 'page_for_posts', array(
    669765                        'type'           => 'option',
    670766                        'capability'     => 'manage_options',
    671                 ) );
    672 
    673                 $this->add_setting( 'page_on_front', array(
    674                         'label'          => __( 'Front page' ),
    675767                //      'theme_supports' => 'static-front-page',
    676                         'section'        => 'static_front_page',
    677                         'control'        => 'dropdown-pages',
    678                         'type'           => 'option',
    679                         'capability'     => 'manage_options',
    680                         'visibility'     => array( 'show_on_front', 'page' ),
    681                 ) );
    682 
    683                 $this->add_setting( 'page_for_posts', array(
    684                         'label'          => __( 'Posts page' ),
    685                 //      'theme_supports' => 'static-front-page',
    686                         'section'        => 'static_front_page',
    687                         'control'        => 'dropdown-pages',
    688                         'type'           => 'option',
    689                         'capability'     => 'manage_options',
    690                         'visibility'     => array( 'show_on_front', 'page' ),
     768                ) );
     769
     770                $this->add_control( 'page_for_posts', array(
     771                        'label'      => __( 'Posts page' ),
     772                        'section'    => 'static_front_page',
     773                        'type'       => 'dropdown-pages',
     774                        'visibility' => array( 'show_on_front', 'page' ),
    691775                ) );
    692776
     
    698782
    699783                $this->add_setting( 'blogname', array(
    700                         'label'          => __( 'Site Title' ),
    701                         'section'        => 'strings',
    702                         'default'        => get_option( 'blogname' ),
    703                         'type'           => 'option',
    704                         'capability'     => 'manage_options',
     784                        'default'    => get_option( 'blogname' ),
     785                        'type'       => 'option',
     786                        'capability' => 'manage_options',
     787                ) );
     788
     789                $this->add_control( 'blogname', array(
     790                        'label'      => __( 'Site Title' ),
     791                        'section'    => 'strings',
    705792                ) );
    706793
    707794                $this->add_setting( 'blogdescription', array(
    708                         'label'          => __( 'Tagline' ),
    709                         'section'        => 'strings',
    710                         'default'        => get_option( 'blogdescription' ),
    711                         'type'           => 'option',
    712                         'capability'     => 'manage_options',
     795                        'default'    => get_option( 'blogdescription' ),
     796                        'type'       => 'option',
     797                        'capability' => 'manage_options',
     798                ) );
     799
     800                $this->add_control( 'blogdescription', array(
     801                        'label'      => __( 'Tagline' ),
     802                        'section'    => 'strings',
    713803                ) );
    714804        }
  • trunk/wp-includes/customize-controls.php

    r20276 r20295  
    9696        $settings = array(
    9797                'preview'  => esc_url( home_url( '/', $scheme ) ),
     98                'settings' => array(),
    9899                'controls' => array(),
    99100                'prefix'   => WP_Customize_Setting::name_prefix,
     
    101102
    102103        foreach ( $this->settings as $id => $setting ) {
    103                 $settings['controls'][ $id ] = array(
     104                $settings['settings'][ $id ] = array(
    104105                        'value'   => $setting->value(),
    105                         'control' => $setting->control,
    106                         'params'  => $setting->control_params,
    107106                );
     107        }
    108108
    109                 if ( $setting->visibility ) {
    110                         if ( is_string( $setting->visibility ) ) {
     109        foreach ( $this->controls as $id => $control ) {
     110                $settings['controls'][ $id ] = $control->json();
     111
     112                if ( $control->visibility ) {
     113                        if ( is_string( $control->visibility ) ) {
    111114                                $settings['controls'][ $id ]['visibility'] = array(
    112                                         'id'    => $setting->visibility,
     115                                        'id'    => $control->visibility,
    113116                                        'value' => true,
    114117                                );
    115118                        } else {
    116119                                $settings['controls'][ $id ]['visibility'] = array(
    117                                         'id'    => $setting->visibility[0],
    118                                         'value' => $setting->visibility[1],
     120                                        'id'    => $control->visibility[0],
     121                                        'value' => $control->visibility[1],
    119122                                );
    120123                        }
  • trunk/wp-includes/js/customize-base.dev.js

    r20257 r20295  
    398398                add: function( id, value ) {
    399399                        if ( this.has( id ) )
    400                                 return;
     400                                return this.value( id );
    401401
    402402                        this._value[ id ] = value;
  • trunk/wp-includes/js/customize-controls.dev.js

    r20290 r20295  
    77         * - method    - The method to use for syncing. Supports 'refresh' and 'postMessage'.
    88         */
    9         api.Control = api.Value.extend({
     9        api.Setting = api.Value.extend({
    1010                initialize: function( id, value, options ) {
    11                         var name = '[name="' + api.settings.prefix + id + '"]';
    12 
    13                         this.params = {};
     11                        var element;
     12
    1413                        api.Value.prototype.initialize.call( this, value, options );
    1514
    1615                        this.id = id;
    17                         this.container = $( '#customize-control-' + id );
    18                         this.element = this.element || new api.Element( this.container.find( name ) );
    19 
    2016                        this.method = this.method || 'refresh';
     17
     18                        element = $( '<input />', {
     19                                type:  'hidden',
     20                                value: this.get(),
     21                                name:  api.settings.prefix + id
     22                        });
     23
     24                        element.appendTo( this.previewer.form );
     25                        this.element = new api.Element( element );
    2126
    2227                        this.element.link( this );
     
    3540        });
    3641
     42        api.Control = api.Class.extend({
     43                initialize: function( id, options ) {
     44                        var control = this,
     45                                nodes, radios, settings;
     46
     47                        this.params = {};
     48                        $.extend( this, options || {} );
     49
     50                        this.id = id;
     51                        this.container = $( '#customize-control-' + id );
     52
     53                        settings = $.map( this.params.settings, function( value ) {
     54                                return value;
     55                        });
     56
     57                        api.apply( api, settings.concat( function() {
     58                                var key;
     59
     60                                control.settings = {};
     61                                for ( key in control.params.settings ) {
     62                                        control.settings[ key ] = api( control.params.settings[ key ] );
     63                                }
     64
     65                                control.setting = control.settings['default'] || null;
     66                                control.ready();
     67                        }) );
     68
     69                        control.elements = [];
     70
     71                        nodes  = this.container.find('[data-customize-setting-link]');
     72                        radios = {};
     73
     74                        nodes.each( function() {
     75                                var node = $(this),
     76                                        name;
     77
     78                                if ( node.is(':radio') ) {
     79                                        name = node.prop('name');
     80                                        if ( radios[ name ] )
     81                                                return;
     82
     83                                        radios[ name ] = true;
     84                                        node = nodes.filter( '[name="' + name + '"]' );
     85                                }
     86
     87                                api( node.data('customizeSettingLink'), function( setting ) {
     88                                        var element = new api.Element( node );
     89                                        control.elements.push( element );
     90                                        element.link( setting ).bind( function( to ) {
     91                                                setting( to );
     92                                        });
     93                                });
     94                        });
     95                },
     96                ready: function() {}
     97        });
     98
    3799        api.ColorControl = api.Control.extend({
    38                 initialize: function( id, value, options ) {
    39                         var self = this,
     100                ready: function() {
     101                        var control = this,
    40102                                picker, ui, text, toggle, update;
    41 
    42                         api.Control.prototype.initialize.call( this, id, value, options );
    43103
    44104                        picker = this.container.find( '.color-picker' );
     
    48108                                color = '#' + color;
    49109                                toggle.css( 'background', color );
    50                                 self.farbtastic.setColor( color );
     110                                control.farbtastic.setColor( color );
    51111                        };
    52 
    53                         this.input = new api.Element( ui.find( 'input' ) ); // Find text input.
    54 
    55                         this.link( this.input );
    56                         this.input.link( this );
    57112
    58113                        picker.on( 'click', 'a', function() {
     
    61116
    62117                        this.farbtastic = $.farbtastic( picker.find('.farbtastic-placeholder'), function( color ) {
    63                                 self.set( color.replace( '#', '' ) );
    64                         });
    65 
    66                         this.bind( update );
    67                         update( this() );
    68                 },
    69                 validate: function( to ) {
    70                         return /^[a-fA-F0-9]{3}([a-fA-F0-9]{3})?$/.test( to ) ? to : null;
     118                                control.setting.set( color.replace( '#', '' ) );
     119                        });
     120
     121                        this.setting.bind( update );
     122                        update( this.setting() );
    71123                }
     124                // ,
     125                //              validate: function( to ) {
     126                //                      return /^[a-fA-F0-9]{3}([a-fA-F0-9]{3})?$/.test( to ) ? to : null;
     127                //              }
    72128        });
    73129
    74130        api.UploadControl = api.Control.extend({
    75                 initialize: function( id, value, options ) {
     131                ready: function() {
    76132                        var control = this;
    77133
    78                         api.Control.prototype.initialize.call( this, id, value, options );
    79134                        this.params.removed = this.params.removed || '';
    80135
     
    82137                                browser: this.container.find('.upload'),
    83138                                success: function( attachment ) {
    84                                         control.set( attachment.url );
     139                                        control.setting.set( attachment.url );
    85140                                }
    86141                        });
     
    88143                        this.remover = this.container.find('.remove');
    89144                        this.remover.click( function( event ) {
    90                                 control.set( control.params.removed );
     145                                control.setting.set( control.params.removed );
    91146                                event.preventDefault();
    92147                        });
    93148
    94                         this.bind( this.removerVisibility );
    95                         this.removerVisibility( this.get() );
     149                        this.removerVisibility = $.proxy( this.removerVisibility, this );
     150                        this.setting.bind( this.removerVisibility );
     151                        this.removerVisibility( this.setting.get() );
    96152
    97153                        if ( this.params.context )
     
    104160
    105161        api.ImageControl = api.UploadControl.extend({
    106                 initialize: function( id, value, options ) {
     162                ready: function( id, value, options ) {
    107163                        var control = this;
    108164
    109                         api.UploadControl.prototype.initialize.call( this, id, value, options );
    110 
    111                         this.thumbnail = this.container.find('.thumbnail img');
    112                         this.bind( this.thumbnailSrc );
     165                        this.thumbnail    = this.container.find('.thumbnail img');
     166                        this.thumbnailSrc = $.proxy( this.thumbnailSrc, this );
     167                        this.setting.bind( this.thumbnailSrc );
    113168
    114169                        this.library = this.container.find('.library');
     
    138193
    139194                        this.library.on( 'click', 'a', function( event ) {
    140                                 control.set( $(this).attr('href') );
     195                                control.setting.set( $(this).attr('href') );
    141196                                event.preventDefault();
    142197                        });
     
    152207        // Change objects contained within the main customize object to Settings.
    153208        api.defaultConstructor = api.Setting;
     209
     210        // Create the collection of Control objects.
     211        api.control = new api.Values({ defaultConstructor: api.Control });
    154212
    155213        api.Previewer = api.Messenger.extend({
     
    273331         * ===================================================================== */
    274332
    275         api.controls = {
     333        api.controlConstructor = {
    276334                color:  api.ColorControl,
    277335                upload: api.UploadControl,
     
    290348                });
    291349
     350                $.each( api.settings.settings, function( id, data ) {
     351                        api.set( id, id, data.value, {
     352                                previewer: previewer
     353                        } );
     354                });
     355
    292356                $.each( api.settings.controls, function( id, data ) {
    293                         var constructor = api.controls[ data.control ] || api.Control,
     357                        var constructor = api.controlConstructor[ data.type ] || api.Control,
    294358                                control;
    295359
    296                         control = api.add( id, new constructor( id, data.value, {
     360                        control = api.control.add( id, new constructor( id, {
    297361                                params: data.params,
    298362                                previewer: previewer
     
    327391
    328392                // Background color uses postMessage by default
    329                 api( 'background_color', function( control ) {
     393                api.control( 'background_color', function( control ) {
    330394                        control.method = 'postMessage';
    331395                });
     396
     397                api.control( 'display_header_text', function( control ) {
     398                        var last = '';
     399
     400                        control.elements[0].unlink();
     401
     402                        control.element = new api.Element( control.container.find('input') );
     403                        control.element.set( 'blank' !== control.setting() );
     404
     405                        control.element.bind( function( to ) {
     406                                if ( ! to )
     407                                        last = api.get( 'header_textcolor' );
     408
     409                                control.setting.set( to ? last : 'blank' );
     410                        });
     411
     412                        control.setting.bind( function( to ) {
     413                                control.element.set( 'blank' !== to );
     414                        });
     415                });
    332416        });
    333417
  • trunk/wp-includes/js/plupload/wp-plupload.dev.js

    r20179 r20295  
    6767
    6868                this.uploader.bind( 'FileUploaded', function( up, file, response ) {
    69                         response = JSON.parse( response.response );
     69                        try {
     70                                response = JSON.parse( response.response );
     71                        } catch ( e ) {
     72                                return self.error( pluploadL10n.default_error, e );
     73                        }
    7074
    7175                        if ( ! response || ! response.type || ! response.data )
Note: See TracChangeset for help on using the changeset viewer.