WordPress.org

Make WordPress Core

Changeset 21383


Ignore:
Timestamp:
08/01/12 06:45:54 (21 months ago)
Author:
koopersmith
Message:

Remove the ability to upload custom headers in the customizer. Properly handle selecting the correct first tab, and removing the control/section if no tabs exist. see #21355.

To check if the control has any potential tabs and headers, added:

  • WP_Customize_Image_Control->prepare_control()
  • WP_Customize_Header_Image_Control->prepare_control()
  • WP_Customize_Header_Image_Control->default_headers
  • WP_Customize_Header_Image_Control->uploaded_headers
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/customize-controls.dev.js

    r21135 r21383  
    221221            }); 
    222222 
    223             // Select a tab 
    224             this.selected = this.tabs[ panels.first().data('customizeTab') ]; 
    225             this.selected.both.addClass('library-selected'); 
    226  
    227223            // Bind tab switch events 
    228224            this.library.children('ul').on( 'click', 'li', function( event ) { 
     
    255251                    this.tabs.uploaded.both.addClass('hidden'); 
    256252            } 
     253 
     254            // Select a tab 
     255            panels.each( function() { 
     256                var tab = control.tabs[ $(this).data('customizeTab') ]; 
     257 
     258                // Select the first visible tab. 
     259                if ( ! tab.link.hasClass('hidden') ) { 
     260                    control.selected = tab; 
     261                    tab.both.addClass('library-selected'); 
     262                    return false; 
     263                } 
     264            }); 
    257265 
    258266            this.dropdownInit(); 
  • trunk/wp-includes/class-wp-customize-control.php

    r21381 r21383  
    478478        $this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) ); 
    479479        $this->add_tab( 'uploaded',   __('Uploaded'),   array( $this, 'tab_uploaded' ) ); 
     480 
     481        // Early priority to occur before $this->manager->prepare_controls(); 
     482        add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 ); 
     483    } 
     484 
     485    /** 
     486     * Prepares the control. 
     487     * 
     488     * If no tabs exist, removes the control from the manager. 
     489     * 
     490     * @since 3.4.1 
     491     */ 
     492    public function prepare_control() { 
     493        if ( ! $this->tabs ) 
     494            $this->manager->remove_control( $this->id ); 
    480495    } 
    481496 
     
    681696 */ 
    682697class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { 
     698    /** 
     699     * The processed default headers. 
     700     * @var array 
     701     */ 
     702    protected $default_headers; 
     703 
     704    /** 
     705     * The uploaded headers. 
     706     * @var array 
     707     */ 
     708    protected $uploaded_headers; 
    683709 
    684710    /** 
     
    710736        ) ); 
    711737 
    712         $this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_headers' ) ); 
     738        // Remove the upload tab. 
     739        $this->remove_tab( 'upload-new' ); 
     740    } 
     741 
     742    /** 
     743     * Prepares the control. 
     744     * 
     745     * If no tabs exist, removes the control from the manager. 
     746     * 
     747     * @since 3.4.1 
     748     */ 
     749    public function prepare_control() { 
     750        global $custom_image_header; 
     751 
     752        // Process default headers and uploaded headers. 
     753        $custom_image_header->process_default_headers(); 
     754        $this->default_headers = $custom_image_header->default_headers; 
     755        $this->uploaded_headers = get_uploaded_header_images(); 
     756 
     757        if ( $this->default_headers ) 
     758            $this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_headers' ) ); 
     759 
     760        if ( ! $this->uploaded_headers ) 
     761            $this->remove_tab( 'uploaded' ); 
     762 
     763        return parent::prepare_control(); 
    713764    } 
    714765 
     
    743794     */ 
    744795    public function tab_uploaded() { 
    745         $headers = get_uploaded_header_images(); 
    746  
    747796        ?><div class="uploaded-target"></div><?php 
    748797 
    749         foreach ( $headers as $choice => $header ) 
     798        foreach ( $this->uploaded_headers as $choice => $header ) 
    750799            $this->print_header_image( $choice, $header ); 
    751800    } 
     
    755804     */ 
    756805    public function tab_default_headers() { 
    757         global $custom_image_header; 
    758         $custom_image_header->process_default_headers(); 
    759  
    760         foreach ( $custom_image_header->default_headers as $choice => $header ) 
     806        foreach ( $this->default_headers as $choice => $header ) 
    761807            $this->print_header_image( $choice, $header ); 
    762808    } 
Note: See TracChangeset for help on using the changeset viewer.