From 61d73832dee849b706c24a5bb2e7036aea6a2880 Mon Sep 17 00:00:00 2001 From: Enej Bajgoric Date: Mon, 9 Mar 2020 09:37:21 +0100 Subject: [PATCH 1/2] Remove PHP Notice when there is no logo an we are looking for an logo ID --- modules/theme-tools/site-logo/inc/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/theme-tools/site-logo/inc/functions.php b/modules/theme-tools/site-logo/inc/functions.php index 3b27b32fb75d8..aaf8ad965f3c5 100644 --- a/modules/theme-tools/site-logo/inc/functions.php +++ b/modules/theme-tools/site-logo/inc/functions.php @@ -103,7 +103,7 @@ function jetpack_has_site_logo() { function jetpack_the_site_logo() { $logo = site_logo()->logo; $logo_id = get_theme_mod( 'custom_logo' ); // Check for WP 4.5 Site Logo - $logo_id = $logo_id ? $logo_id : $logo['id']; // Use WP Core logo if present, otherwise use Jetpack's. + $logo_id = $logo_id ? $logo_id : ( isset( $logo['id'] ) ? $logo['id'] : false ); // Use WP Core logo if present, otherwise use Jetpack's. $size = site_logo()->theme_size(); $html = ''; From a023193018a143401a1e8747075cf5b180fd163c Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Tue, 17 Mar 2020 20:06:23 +0300 Subject: [PATCH 2/2] Refactored the jetpack_the_site_logo logic. --- .../theme-tools/site-logo/inc/functions.php | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/modules/theme-tools/site-logo/inc/functions.php b/modules/theme-tools/site-logo/inc/functions.php index aaf8ad965f3c5..f22829d226a45 100644 --- a/modules/theme-tools/site-logo/inc/functions.php +++ b/modules/theme-tools/site-logo/inc/functions.php @@ -101,41 +101,45 @@ function jetpack_has_site_logo() { * @since 1.0 */ function jetpack_the_site_logo() { - $logo = site_logo()->logo; - $logo_id = get_theme_mod( 'custom_logo' ); // Check for WP 4.5 Site Logo - $logo_id = $logo_id ? $logo_id : ( isset( $logo['id'] ) ? $logo['id'] : false ); // Use WP Core logo if present, otherwise use Jetpack's. - $size = site_logo()->theme_size(); - $html = ''; + $size = site_logo()->theme_size(); // If no logo is set, but we're in the Customizer, leave a placeholder (needed for the live preview). - if ( ! jetpack_has_site_logo() ) { - if ( jetpack_is_customize_preview() ) { - $html = sprintf( + if ( + ! jetpack_has_site_logo() + && jetpack_is_customize_preview() + ) { + /* + * Reason: the output is escaped in the sprintf. + * phpcs:disable WordPress.Security.EscapeOutput + */ + /** This filter is documented in modules/theme-tools/site-logo/inc/functions.php */ + echo apply_filters( + 'jetpack_the_site_logo', + sprintf( '', esc_url( home_url( '/' ) ), esc_attr( $size ) - ); - } + ), + array(), + $size + ); + /* phpcs:enable WordPress.Security.EscapeOutput */ + return; } - // We have a logo. Logo is go. - else { - $html = sprintf( - '', - esc_url( home_url( '/' ) ), - wp_get_attachment_image( - $logo_id, - $size, - false, - array( - 'class' => "site-logo attachment-$size", - 'data-size' => $size, - 'itemprop' => 'logo', - ) - ) - ); + // Check for WP 4.5 Site Logo and Jetpack logo. + $logo_id = get_theme_mod( 'custom_logo' ); + $jetpack_logo = site_logo()->logo; + + // Use WP Core logo if present, otherwise use Jetpack's. + if ( ! $logo_id && isset( $jetpack_logo['id'] ) ) { + $logo_id = $jetpack_logo['id']; } + /* + * Reason: the output is escaped in the sprintf. + * phpcs:disable WordPress.Security.EscapeOutput + */ /** * Filter the Site Logo output. * @@ -144,10 +148,29 @@ function jetpack_the_site_logo() { * @since 3.2.0 * * @param string $html Site Logo HTML output. - * @param array $logo Array of Site Logo details. + * @param array $jetpack_logo Array of Site Logo details. * @param string $size Size specified in add_theme_support declaration, or 'thumbnail' default. */ - echo apply_filters( 'jetpack_the_site_logo', $html, $logo, $size ); + echo apply_filters( + 'jetpack_the_site_logo', + sprintf( + '', + esc_url( home_url( '/' ) ), + wp_get_attachment_image( + $logo_id, + $size, + false, + array( + 'class' => "site-logo attachment-$size", + 'data-size' => $size, + 'itemprop' => 'logo', + ) + ) + ), + $jetpack_logo, + $size + ); + /* phpcs:enable WordPress.Security.EscapeOutput */ } /**