From bf458c2c1a3d0153d01732e13f1e260ad3ea0432 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Wed, 1 Aug 2012 06:45:54 +0000 Subject: [PATCH] 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 git-svn-id: https://develop.svn.wordpress.org/trunk@21383 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/js/customize-controls.dev.js | 16 ++++-- wp-includes/class-wp-customize-control.php | 62 +++++++++++++++++++--- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/wp-admin/js/customize-controls.dev.js b/wp-admin/js/customize-controls.dev.js index c37e43bd02..900ab13c01 100644 --- a/wp-admin/js/customize-controls.dev.js +++ b/wp-admin/js/customize-controls.dev.js @@ -220,10 +220,6 @@ }; }); - // Select a tab - this.selected = this.tabs[ panels.first().data('customizeTab') ]; - this.selected.both.addClass('library-selected'); - // Bind tab switch events this.library.children('ul').on( 'click', 'li', function( event ) { var id = $(this).data('customizeTab'), @@ -255,6 +251,18 @@ this.tabs.uploaded.both.addClass('hidden'); } + // Select a tab + panels.each( function() { + var tab = control.tabs[ $(this).data('customizeTab') ]; + + // Select the first visible tab. + if ( ! tab.link.hasClass('hidden') ) { + control.selected = tab; + tab.both.addClass('library-selected'); + return false; + } + }); + this.dropdownInit(); }, success: function( attachment ) { diff --git a/wp-includes/class-wp-customize-control.php b/wp-includes/class-wp-customize-control.php index 20213fb890..f9a5cc5dd0 100644 --- a/wp-includes/class-wp-customize-control.php +++ b/wp-includes/class-wp-customize-control.php @@ -477,6 +477,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.1 + */ + public function prepare_control() { + if ( ! $this->tabs ) + $this->manager->remove_control( $this->id ); } /** @@ -680,6 +695,17 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { * @since 3.4.0 */ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { + /** + * The processed default headers. + * @var array + */ + protected $default_headers; + + /** + * The uploaded headers. + * @var array + */ + protected $uploaded_headers; /** * Constructor. @@ -709,7 +735,32 @@ 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.1 + */ + public function prepare_control() { + global $custom_image_header; + + // 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(); } /** @@ -742,11 +793,9 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { * @since 3.4.0 */ public function tab_uploaded() { - $headers = get_uploaded_header_images(); - ?>
$header ) + foreach ( $this->uploaded_headers as $choice => $header ) $this->print_header_image( $choice, $header ); } @@ -754,10 +803,7 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { * @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