Make WordPress Core


Ignore:
Timestamp:
04/20/2012 02:39:55 AM (14 years ago)
Author:
koopersmith
Message:

Theme Customizer: Improve image picker control. see #19910.

Overhauled image pickers:

  • Add support for drag and drop uploads to image controls.
  • Improve the 'uploaded' tab in image controls: automatically add images uploaded during the current session, hide the tab when no uploaded images exist.
  • Move the header image control to the WP_Customize_Header_Image_Control class. Remove wp_customize_print_uploaded_headers() and wp_customize_print_uploaded_headers() functions.
  • Abstract the dropdown functionality from the color picker to the .dropdown class.
  • In wp.Uploader, unset element keys if passed an empty jQuery collection.
File:
1 edited

Legend:

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

    r20527 r20545  
    181181                <label>
    182182                    <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    183                     <a href="#" class="color-picker-toggle">
    184                         <div class="color-picker-spot"></div>
    185                         <div class="color-picker-dropdown"></div>
    186                     </a>
     183                    <div class="dropdown color-picker-toggle">
     184                        <div class="dropdown-content color-picker-spot"></div>
     185                        <div class="dropdown-arrow"></div>
     186                    </div>
    187187                    <div class="color-picker-control color-picker-hex">
    188188                        <span>#</span>
     
    292292class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
    293293    public $type = 'image';
    294     public $tabs = array();
    295294    public $get_url;
     295
     296    protected $tabs = array();
     297
     298    public function __construct( $manager, $id, $args ) {
     299        parent::__construct( $manager, $id, $args );
     300
     301        $this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) );
     302        $this->add_tab( 'uploaded',   __('Uploaded'),   array( $this, 'tab_uploaded' ) );
     303    }
    296304
    297305    public function render_content() {
     
    304312            <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    305313
    306             <div class="thumbnail">
    307                 <?php if ( empty( $src ) ): ?>
    308                     <img style="display:none;" />
    309                 <?php else: ?>
    310                     <img src="<?php echo esc_url( $src ); ?>" />
    311                 <?php endif; ?>
    312             </div>
    313 
    314             <div class="actions">
    315                 <a href="#" class="upload"><?php _e( 'Upload New' ); ?></a>
    316                 <a href="#" class="change"><?php _e( 'Change Image' ); ?></a>
    317                 <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
     314
     315            <div class="dropdown preview-thumbnail">
     316                <div class="dropdown-content">
     317                    <?php if ( empty( $src ) ): ?>
     318                        <img style="display:none;" />
     319                    <?php else: ?>
     320                        <img src="<?php echo esc_url( $src ); ?>" />
     321                    <?php endif; ?>
     322                </div>
     323                <div class="dropdown-arrow"></div>
    318324            </div>
    319325
    320326            <div class="library">
    321327                <ul>
    322                     <?php foreach ( $this->tabs as $tab ): ?>
    323                         <li data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
    324                             <?php echo esc_html( $tab[1] ); ?>
     328                    <?php foreach ( $this->tabs as $id => $tab ): ?>
     329                        <li data-customize-tab='<?php echo esc_attr( $id ); ?>'>
     330                            <?php echo esc_html( $tab['label'] ); ?>
    325331                        </li>
    326332                    <?php endforeach; ?>
    327333                </ul>
    328                 <?php foreach ( $this->tabs as $tab ): ?>
    329                     <div class="library-content" data-customize-tab='<?php echo esc_attr( $tab[0] ); ?>'>
    330                         <?php call_user_func( $tab[2] ); ?>
     334                <?php foreach ( $this->tabs as $id => $tab ): ?>
     335                    <div class="library-content" data-customize-tab='<?php echo esc_attr( $id ); ?>'>
     336                        <?php call_user_func( $tab['callback'] ); ?>
    331337                    </div>
    332338                <?php endforeach; ?>
    333339            </div>
     340
     341            <div class="actions">
     342                <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
     343            </div>
    334344        </label>
    335345        <?php
    336346    }
     347
     348    public function add_tab( $id, $label, $callback ) {
     349        $this->tabs[ $id ] = array(
     350            'label'    => $label,
     351            'callback' => $callback,
     352        );
     353    }
     354
     355    public function remove_tab( $id ) {
     356        unset( $this->tabs[ $id ] );
     357    }
     358
     359    public function tab_upload_new() {
     360        ?>
     361        <div class="upload-dropzone">
     362            <?php _e('Drop a file here or <a href="#" class="upload">select a file</a>.'); ?>
     363        </div>
     364        <?php
     365    }
     366
     367    public function tab_uploaded() {
     368        ?>
     369        <div class="uploaded-target"></div>
     370        <?php
     371    }
    337372}
     373
     374class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
     375    public function __construct( $manager ) {
     376        parent::__construct( $manager, 'header_image', array(
     377            'label'   => __( 'Header Image' ),
     378            'section' => 'header',
     379            'context' => 'custom-header',
     380            'removed' => 'remove-header',
     381            'get_url' => 'get_header_image',
     382        ) );
     383
     384        $this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_headers' ) );
     385    }
     386
     387    public function tab_uploaded() {
     388        $headers = get_uploaded_header_images();
     389
     390        ?><div class="uploaded-target"></div><?php
     391
     392        foreach ( $headers as $header ) : ?>
     393            <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>">
     394                <img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" />
     395            </a>
     396        <?php endforeach;
     397    }
     398
     399    public function tab_default_headers() {
     400        global $custom_image_header;
     401        $custom_image_header->process_default_headers();
     402
     403        foreach ( $custom_image_header->default_headers as $header ) : ?>
     404            <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>">
     405                <img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" />
     406            </a>
     407        <?php endforeach;
     408    }
     409}
Note: See TracChangeset for help on using the changeset viewer.