WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/09/2016 11:43:49 PM (4 years ago)
Author:
obenland
Message:

Customize: Only add custom logo’s header text control if needed.

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r36909 r36915  
    17331733
    17341734/**
     1735 * Adds CSS to hide header text for custom logo, based on Customizer setting.
     1736 *
     1737 * @since 4.5.0
     1738 * @access private
     1739 */
     1740function _custom_logo_header_styles() {
     1741    if ( ! current_theme_supports( 'custom-header', 'header-text' ) && get_theme_support( 'custom-logo', 'header-text' ) && ! get_theme_mod( 'header_text', true ) ) {
     1742        $classes = (array) get_theme_support( 'custom-logo', 'header-text' );
     1743        $classes = array_map( 'sanitize_html_class', $classes );
     1744        $classes = '.' . implode( ', .', $classes );
     1745
     1746        ?>
     1747        <!-- Custom Logo: hide header text -->
     1748        <style id="custom-logo-css" type="text/css">
     1749            <?php echo $classes; ?> {
     1750                position: absolute;
     1751                clip: rect(1px, 1px, 1px, 1px);
     1752            }
     1753        </style>
     1754    <?php
     1755    }
     1756}
     1757
     1758/**
    17351759 * Gets the theme support arguments passed when registering that support
    17361760 *
     
    19281952 * @since 3.0.0
    19291953 * @since 4.3.0 Also removes `header_image_data`.
     1954 * @since 4.5.0 Also removes custom logo theme mods.
    19301955 *
    19311956 * @param int $id The attachment id.
     
    19351960    $header_image     = get_header_image();
    19361961    $background_image = get_background_image();
     1962    $custom_logo_id   = get_theme_mod( 'custom_logo' );
     1963
     1964    if ( $custom_logo_id && $custom_logo_id == $id ) {
     1965        remove_theme_mod( 'custom_logo' );
     1966        remove_theme_mod( 'header_text' );
     1967    }
    19371968
    19381969    if ( $header_image && $header_image == $attachment_image ) {
Note: See TracChangeset for help on using the changeset viewer.