Make WordPress Core

Changeset 58213


Ignore:
Timestamp:
05/27/2024 04:39:13 PM (7 months ago)
Author:
joedolson
Message:

Themes: Accessibility: Logo block returns empty link when image not set.

The logo block does not use theme mods, and instead saves a site-wide option site_logo to use as the site logo.

Add handling for cases where the logo image does not exist and delete the site_logo option when the attachment configured as site logo is deleted.

Props afercia, joedolson, khokansardar, SergeyBiryukov.
Fixes #60922.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

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

    r57789 r58213  
    10251025
    10261026    $custom_logo_id = get_theme_mod( 'custom_logo' );
     1027    $is_image       = wp_attachment_is_image( $custom_logo_id );
    10271028
    10281029    if ( $switched_blog ) {
     
    10301031    }
    10311032
    1032     return (bool) $custom_logo_id;
     1033    return $is_image;
    10331034}
    10341035
     
    10531054    }
    10541055
    1055     $custom_logo_id = get_theme_mod( 'custom_logo' );
    1056 
    10571056    // We have a logo. Logo is go.
    1058     if ( $custom_logo_id ) {
     1057    if ( has_custom_logo() ) {
     1058        $custom_logo_id   = get_theme_mod( 'custom_logo' );
    10591059        $custom_logo_attr = array(
    10601060            'class'   => 'custom-logo',
     
    10981098        $image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr );
    10991099
    1100         if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
    1101             // If on the home page, don't link the logo to home.
    1102             $html = sprintf(
    1103                 '<span class="custom-logo-link">%1$s</span>',
    1104                 $image
    1105             );
    1106         } else {
    1107             $aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : '';
    1108 
    1109             $html = sprintf(
    1110                 '<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
    1111                 esc_url( home_url( '/' ) ),
    1112                 $aria_current,
    1113                 $image
    1114             );
     1100        // Check that we have a proper HTML img element.
     1101        if ( $image ) {
     1102
     1103            if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
     1104                // If on the home page, don't link the logo to home.
     1105                $html = sprintf(
     1106                    '<span class="custom-logo-link">%1$s</span>',
     1107                    $image
     1108                );
     1109            } else {
     1110                $aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : '';
     1111
     1112                $html = sprintf(
     1113                    '<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
     1114                    esc_url( home_url( '/' ) ),
     1115                    $aria_current,
     1116                    $image
     1117                );
     1118            }
    11151119        }
    11161120    } elseif ( is_customize_preview() ) {
  • trunk/src/wp-includes/theme.php

    r57987 r58213  
    34353435 * @since 4.3.0 Also removes `header_image_data`.
    34363436 * @since 4.5.0 Also removes custom logo theme mods.
     3437 * @since 6.6.0 Also removes `site_logo` option set by the site logo block.
    34373438 *
    34383439 * @param int $id The attachment ID.
     
    34433444    $background_image = get_background_image();
    34443445    $custom_logo_id   = get_theme_mod( 'custom_logo' );
     3446    $site_logo_id     = get_option( 'site_logo' );
    34453447
    34463448    if ( $custom_logo_id && $custom_logo_id == $id ) {
    34473449        remove_theme_mod( 'custom_logo' );
    34483450        remove_theme_mod( 'header_text' );
     3451    }
     3452
     3453    if ( $site_logo_id && $site_logo_id == $id ) {
     3454        delete_option( 'site_logo' );
    34493455    }
    34503456
Note: See TracChangeset for help on using the changeset viewer.