From 6d951b3c5d5ac8bc01643a462c1408df48bb1c58 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Wed, 9 Mar 2016 23:43:49 +0000 Subject: [PATCH] =?UTF-8?q?Customize:=20Only=20add=20custom=20logo?= =?UTF-8?q?=E2=80=99s=20header=20text=20control=20if=20needed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dissolves `WP_CustomLogo` and adopts a structure similar to custom header and background (See `_delete_attachment_theme_mod()`). The option to hide header text only gets added if it’s not already part of custom header, and only if selectors have been registered when theme support for custom logos was declared. Themes can add `postMessage` support for it as well. Example: {{{ add_theme_support( 'custom-logo', array(     'size' => ‘large’,     'header-text' => array( 'site-title', 'site-description' ), ) ); }}} See #33755. git-svn-id: https://develop.svn.wordpress.org/trunk@36915 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/admin.php | 3 - .../includes/class-wp-custom-logo.php | 109 ------------------ .../class-wp-customize-manager.php | 7 +- src/wp-includes/default-filters.php | 1 + src/wp-includes/general-template.php | 3 +- src/wp-includes/theme.php | 31 +++++ tests/phpunit/tests/image/custom_logo.php | 45 -------- 7 files changed, 36 insertions(+), 163 deletions(-) delete mode 100644 src/wp-admin/includes/class-wp-custom-logo.php delete mode 100644 tests/phpunit/tests/image/custom_logo.php diff --git a/src/wp-admin/includes/admin.php b/src/wp-admin/includes/admin.php index 7d2437b2b8..a44abba917 100644 --- a/src/wp-admin/includes/admin.php +++ b/src/wp-admin/includes/admin.php @@ -72,9 +72,6 @@ require_once(ABSPATH . 'wp-admin/includes/user.php'); /** WordPress Site Icon API */ require_once(ABSPATH . 'wp-admin/includes/class-wp-site-icon.php'); -/** WordPress Custom Logo API */ -require_once(ABSPATH . 'wp-admin/includes/class-wp-custom-logo.php'); - /** WordPress Update Administration API */ require_once(ABSPATH . 'wp-admin/includes/update.php'); diff --git a/src/wp-admin/includes/class-wp-custom-logo.php b/src/wp-admin/includes/class-wp-custom-logo.php deleted file mode 100644 index 5549eefcb9..0000000000 --- a/src/wp-admin/includes/class-wp-custom-logo.php +++ /dev/null @@ -1,109 +0,0 @@ - - - - 'title_tagline', ) ); - // Add a setting to hide header text if the theme isn't supporting the feature itself. - // @todo - if ( ! current_theme_supports( 'custom-header' ) ) { + // Add a setting to hide header text if the theme doesn't support custom headers. + if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) { $this->add_setting( 'header_text', array( + 'theme_supports' => array( 'custom-logo', 'header-text' ), 'default' => 1, 'sanitize_callback' => 'absint', - 'transport' => 'postMessage', ) ); $this->add_control( 'header_text', array( diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 76111ff428..2ae86d88f5 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -371,6 +371,7 @@ add_action( 'parse_request', 'rest_api_loaded' ); */ // Theme add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); +add_action( 'wp_head', '_custom_logo_header_styles' ); add_action( 'plugins_loaded', '_wp_customize_include' ); add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' ); add_action( 'delete_attachment', '_delete_attachment_theme_mod' ); diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 9973cb5623..87808129ab 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -880,8 +880,7 @@ function get_custom_logo( $blog_id = 0 ) { if ( is_multisite() && ms_is_switched() ) { restore_current_blog(); } - $size = get_theme_support( 'custom-logo' ); - $size = $size[0]['size']; + $size = get_theme_support( 'custom-logo', 'size' ); // We have a logo. Logo is go. if ( $custom_logo_id ) { diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index ba0efbd6d3..15681e5a39 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -1731,6 +1731,30 @@ function _custom_header_background_just_in_time() { } } +/** + * Adds CSS to hide header text for custom logo, based on Customizer setting. + * + * @since 4.5.0 + * @access private + */ +function _custom_logo_header_styles() { + if ( ! current_theme_supports( 'custom-header', 'header-text' ) && get_theme_support( 'custom-logo', 'header-text' ) && ! get_theme_mod( 'header_text', true ) ) { + $classes = (array) get_theme_support( 'custom-logo', 'header-text' ); + $classes = array_map( 'sanitize_html_class', $classes ); + $classes = '.' . implode( ', .', $classes ); + + ?> + + + custom_logo = null; - $this->remove_added_uploads(); - parent::tearDown(); - } - - function test_delete_attachment_data() { - $attachment_id = $this->_insert_attachment(); - set_theme_mod( 'custom_logo', $attachment_id ); - - wp_delete_attachment( $attachment_id, true ); - - $this->assertFalse( get_theme_mod( 'custom_logo' ) ); - } - - function _insert_attachment() { - if ( $this->attachment_id ) { - return $this->attachment_id; - } - - $filename = DIR_TESTDATA . '/images/test-image.jpg'; - $contents = file_get_contents( $filename ); - - $upload = wp_upload_bits( basename( $filename ), null, $contents ); - - $this->attachment_id = $this->_make_attachment( $upload ); - return $this->attachment_id; - } -}