@@ -401,12 +606,21 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
}
}
+ /**
+ * @since 3.4.0
+ */
public function tab_uploaded() {
?>
__( 'Background Image' ),
@@ -431,6 +661,9 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
$this->add_tab( 'default', __('Default'), array( $this, 'tab_default_background' ) );
}
+ /**
+ * @since 3.4.0
+ */
public function tab_uploaded() {
$backgrounds = get_posts( array(
'post_type' => 'attachment',
@@ -449,12 +682,46 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
$this->print_tab_image( esc_url_raw( $background->guid ) );
}
+ /**
+ * @since 3.4.0
+ * @uses WP_Customize_Image_Control::print_tab_image()
+ */
public function tab_default_background() {
$this->print_tab_image( $this->setting->default );
}
}
+/**
+ * Customize Header Image Control Class
+ *
+ * @package WordPress
+ * @subpackage Customize
+ * @since 3.4.0
+ */
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;
+
+ /**
+ * Constructor.
+ *
+ * @since 3.4.0
+ * @uses WP_Customize_Image_Control::__construct()
+ * @uses WP_Customize_Image_Control::add_tab()
+ *
+ * @param WP_Customize_Manager $manager
+ */
public function __construct( $manager ) {
parent::__construct( $manager, 'header_image', array(
'label' => __( 'Header Image' ),
@@ -474,9 +741,42 @@ 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();
}
+ /**
+ * @since 3.4.0
+ *
+ * @param mixed $choice Which header image to select. (@see Custom_Image_Header::get_header_image() )
+ * @param array $header
+ */
public function print_header_image( $choice, $header ) {
$header['url'] = set_url_scheme( $header['url'] );
$header['thumbnail_url'] = set_url_scheme( $header['thumbnail_url'] );
@@ -497,20 +797,21 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
$header )
+ foreach ( $this->uploaded_headers as $choice => $header )
$this->print_header_image( $choice, $header );
}
+ /**
+ * @since 3.4.0
+ */
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