From 68197542eba6c334c56b68e36bb7c4359889b9e3 Mon Sep 17 00:00:00 2001 From: joedolson Date: Mon, 27 May 2024 16:41:10 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@58213 git-svn-id: http://core.svn.wordpress.org/trunk@57676 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 40 ++++++++++++++++++-------------- wp-includes/theme.php | 6 +++++ wp-includes/version.php | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 6c3a1ff991..1c795b06ca 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -1024,12 +1024,13 @@ function has_custom_logo( $blog_id = 0 ) { } $custom_logo_id = get_theme_mod( 'custom_logo' ); + $is_image = wp_attachment_is_image( $custom_logo_id ); if ( $switched_blog ) { restore_current_blog(); } - return (bool) $custom_logo_id; + return $is_image; } /** @@ -1052,10 +1053,9 @@ function get_custom_logo( $blog_id = 0 ) { $switched_blog = true; } - $custom_logo_id = get_theme_mod( 'custom_logo' ); - // We have a logo. Logo is go. - if ( $custom_logo_id ) { + if ( has_custom_logo() ) { + $custom_logo_id = get_theme_mod( 'custom_logo' ); $custom_logo_attr = array( 'class' => 'custom-logo', 'loading' => false, @@ -1097,21 +1097,25 @@ function get_custom_logo( $blog_id = 0 ) { */ $image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ); - if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) { - // If on the home page, don't link the logo to home. - $html = sprintf( - '%1$s', - $image - ); - } else { - $aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : ''; + // Check that we have a proper HTML img element. + if ( $image ) { - $html = sprintf( - '%3$s', - esc_url( home_url( '/' ) ), - $aria_current, - $image - ); + if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) { + // If on the home page, don't link the logo to home. + $html = sprintf( + '%1$s', + $image + ); + } else { + $aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : ''; + + $html = sprintf( + '%3$s', + esc_url( home_url( '/' ) ), + $aria_current, + $image + ); + } } } elseif ( is_customize_preview() ) { // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 11b7bd9aa3..330c36d3f5 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -3434,6 +3434,7 @@ function get_registered_theme_feature( $feature ) { * @since 3.0.0 * @since 4.3.0 Also removes `header_image_data`. * @since 4.5.0 Also removes custom logo theme mods. + * @since 6.6.0 Also removes `site_logo` option set by the site logo block. * * @param int $id The attachment ID. */ @@ -3442,12 +3443,17 @@ function _delete_attachment_theme_mod( $id ) { $header_image = get_header_image(); $background_image = get_background_image(); $custom_logo_id = get_theme_mod( 'custom_logo' ); + $site_logo_id = get_option( 'site_logo' ); if ( $custom_logo_id && $custom_logo_id == $id ) { remove_theme_mod( 'custom_logo' ); remove_theme_mod( 'header_text' ); } + if ( $site_logo_id && $site_logo_id == $id ) { + delete_option( 'site_logo' ); + } + if ( $header_image && $header_image == $attachment_image ) { remove_theme_mod( 'header_image' ); remove_theme_mod( 'header_image_data' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index e17b4ce99d..1ad6699e62 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-58212'; +$wp_version = '6.6-alpha-58213'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.