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

Site Logo: Update url for site icon settings with fallback for WP core versions earlier than 6.5 #59485

Merged
merged 2 commits into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/compat/wordpress-6.5/compat.php
Expand Up @@ -36,3 +36,18 @@ function array_is_list( $arr ) {
return true;
}
}

/**
* Sets a global JS variable used to flag whether to direct the Site Logo block's admin urls
* to the Customizer. This allows Gutenberg running on versions of WordPress < 6.5.0 to
* support the previous location for the Site Icon settings. This function should not be
* backported to core, and should be removed when the required WP core version for Gutenberg
* is >= 6.5.0.
*/
function gutenberg_add_use_customizer_site_logo_url_flag() {
if ( ! is_wp_version_compatible( '6.5' ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalUseCustomizerSiteLogoUrl = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_add_use_customizer_site_logo_url_flag' );
13 changes: 9 additions & 4 deletions packages/block-library/src/site-logo/edit.js
Expand Up @@ -268,6 +268,14 @@ const SiteLogo = ( {
</ResizableBox>
);

// Support the previous location for the Site Icon settings. To be removed
// when the required WP core version for Gutenberg is >= 6.5.0.
const shouldUseNewUrl = ! window?.__experimentalUseCustomizerSiteLogoUrl;

const siteIconSettingsUrl = shouldUseNewUrl
? siteUrl + '/wp-admin/options-general.php'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shame there's no id we can use as a hash value. The other options have them and are used in core, e.g., #home in esc_url( admin_url( 'options-general.php' ) . '#home' ).

wp-admin/options-general.php#choose-from-library-button is possible, but it's not great.

Which reminds me that Gutenberg should probably be using admin_url() or get_admin_url() for such links.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which reminds me that Gutenberg should probably be using admin_url() or get_admin_url() for such links.

Great point — that could be a good thing to look into for 6.6, since folks should be able to filter admin urls and have it propagate to links in Gutenberg 👍

: siteUrl + '/wp-admin/customize.php?autofocus[section]=title_tagline';

const syncSiteIconHelpText = createInterpolateElement(
__(
'Site Icons are what you see in browser tabs, bookmark bars, and within the WordPress mobile apps. To use a custom icon that is different from your site logo, use the <a>Site Icon settings</a>.'
Expand All @@ -276,10 +284,7 @@ const SiteLogo = ( {
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={
siteUrl +
'/wp-admin/customize.php?autofocus[section]=title_tagline'
}
href={ siteIconSettingsUrl }
target="_blank"
rel="noopener noreferrer"
/>
Expand Down