From 18cad0b1a4bae4fe6d6d3e137c5732c24d963a8b Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Fri, 1 Mar 2024 11:25:50 +1100
Subject: [PATCH 1/2] Site Logo: Update url for site icon settings with
fallback for WP core versions earlier than 6.5
---
lib/experimental/editor-settings.php | 6 ++++++
packages/block-library/src/site-logo/edit.js | 13 +++++++++----
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php
index f5d40ae8a2110..5b1bcff54a986 100644
--- a/lib/experimental/editor-settings.php
+++ b/lib/experimental/editor-settings.php
@@ -28,6 +28,12 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
+
+ // Support the previous location for the Site Icon settings. To be removed
+ // when the required WP core version for Gutenberg is >= 6.5.0.
+ if ( ! is_wp_version_compatible( '6.5' ) ) {
+ wp_add_inline_script( 'wp-block-editor', 'window.__experimentalUseCustomizerSiteLogoUrl = true', 'before' );
+ }
}
add_action( 'admin_init', 'gutenberg_enable_experiments' );
diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js
index fe4146406ddf6..079811f0aae95 100644
--- a/packages/block-library/src/site-logo/edit.js
+++ b/packages/block-library/src/site-logo/edit.js
@@ -268,6 +268,14 @@ const SiteLogo = ( {
);
+ // 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'
+ : 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 Site Icon settings.'
@@ -276,10 +284,7 @@ const SiteLogo = ( {
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
From b8d9ae2d1825815fcbe69fbebe1380bf035fc4ff Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Fri, 1 Mar 2024 13:55:19 +1100
Subject: [PATCH 2/2] Move PHP changes to compat.php file
---
lib/compat/wordpress-6.5/compat.php | 15 +++++++++++++++
lib/experimental/editor-settings.php | 6 ------
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/lib/compat/wordpress-6.5/compat.php b/lib/compat/wordpress-6.5/compat.php
index 7844792712589..39edaef83e5cc 100644
--- a/lib/compat/wordpress-6.5/compat.php
+++ b/lib/compat/wordpress-6.5/compat.php
@@ -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' );
diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php
index 5b1bcff54a986..f5d40ae8a2110 100644
--- a/lib/experimental/editor-settings.php
+++ b/lib/experimental/editor-settings.php
@@ -28,12 +28,6 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
-
- // Support the previous location for the Site Icon settings. To be removed
- // when the required WP core version for Gutenberg is >= 6.5.0.
- if ( ! is_wp_version_compatible( '6.5' ) ) {
- wp_add_inline_script( 'wp-block-editor', 'window.__experimentalUseCustomizerSiteLogoUrl = true', 'before' );
- }
}
add_action( 'admin_init', 'gutenberg_enable_experiments' );