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
This commit is contained in:
parent
f6973306ea
commit
68197542eb
|
@ -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(
|
||||
'<span class="custom-logo-link">%1$s</span>',
|
||||
$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(
|
||||
'<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
|
||||
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(
|
||||
'<span class="custom-logo-link">%1$s</span>',
|
||||
$image
|
||||
);
|
||||
} else {
|
||||
$aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : '';
|
||||
|
||||
$html = sprintf(
|
||||
'<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
|
||||
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).
|
||||
|
|
|
@ -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' );
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue