Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PHP Notice when there is no logo an we are looking for an logo ID #14924

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 51 additions & 28 deletions modules/theme-tools/site-logo/inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : $logo['id']; // 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(
'<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>',
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(
'<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>',
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.
*
Expand All @@ -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(
'<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>',
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 */
}

/**
Expand Down