WordPress 3.4.2
[autoinstalls/wordpress.git] / wp-includes / class-wp-customize-control.php
index 5ded24ca16ee4cdc759272dcdada91006028d892..3189332ac099d678b3d0fa100a14f734c75e0bf2 100644 (file)
@@ -321,6 +321,21 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
 
                $this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) );
                $this->add_tab( 'uploaded',   __('Uploaded'),   array( $this, 'tab_uploaded' ) );
+
+               // Early priority to occur before $this->manager->prepare_controls();
+               add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 );
+       }
+
+       /**
+        * Prepares the control.
+        *
+        * If no tabs exist, removes the control from the manager.
+        *
+        * @since 3.4.2
+        */
+       public function prepare_control() {
+               if ( ! $this->tabs )
+                       $this->manager->remove_control( $this->id );
        }
 
        public function to_json() {
@@ -455,6 +470,20 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
 }
 
 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
+       /**
+        * The processed default headers.
+        * @since 3.4.2
+        * @var array
+        */
+       protected $default_headers;
+
+       /**
+        * The uploaded headers.
+        * @since 3.4.2
+        * @var array
+        */
+       protected $uploaded_headers;
+
        public function __construct( $manager ) {
                parent::__construct( $manager, 'header_image', array(
                        'label'    => __( 'Header Image' ),
@@ -474,7 +503,34 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
                        )
                ) );
 
-               $this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_headers' ) );
+               // Remove the upload tab.
+               $this->remove_tab( 'upload-new' );
+       }
+
+       /**
+        * Prepares the control.
+        *
+        * If no tabs exist, removes the control from the manager.
+        *
+        * @since 3.4.2
+        */
+       public function prepare_control() {
+               global $custom_image_header;
+               if ( empty( $custom_image_header ) )
+                       return parent::prepare_control();
+
+               // Process default headers and uploaded headers.
+               $custom_image_header->process_default_headers();
+               $this->default_headers = $custom_image_header->default_headers;
+               $this->uploaded_headers = get_uploaded_header_images();
+
+               if ( $this->default_headers )
+                       $this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_headers' ) );
+
+               if ( ! $this->uploaded_headers )
+                       $this->remove_tab( 'uploaded' );
+
+               return parent::prepare_control();
        }
 
        public function print_header_image( $choice, $header ) {
@@ -498,19 +554,14 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
        }
 
        public function tab_uploaded() {
-               $headers = get_uploaded_header_images();
-
                ?><div class="uploaded-target"></div><?php
 
-               foreach ( $headers as $choice => $header )
+               foreach ( $this->uploaded_headers as $choice => $header )
                        $this->print_header_image( $choice, $header );
        }
 
        public function tab_default_headers() {
-               global $custom_image_header;
-               $custom_image_header->process_default_headers();
-
-               foreach ( $custom_image_header->default_headers as $choice => $header )
+               foreach ( $this->default_headers as $choice => $header )
                        $this->print_header_image( $choice, $header );
        }
 }
\ No newline at end of file