From dc4bd0502d9ef354a3f9556d1a36aa1a60d526b8 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 29 Oct 2024 13:45:27 +1100 Subject: [PATCH] Global styles: move preload paths filter to 6.7 (previously 6.8) (#66543) * Given that this fixes a 6.7 regression move the code into 6.7 compat. * Move for loop into context block * Move backport log to 6.7 Co-authored-by: ramonjd Co-authored-by: aaronrobertshaw Co-authored-by: andrewserong --- backport-changelog/{6.8 => 6.7}/7661.md | 1 + lib/compat/wordpress-6.7/rest-api.php | 19 ++++++++++++++++ lib/compat/wordpress-6.8/preload.php | 29 ------------------------- lib/load.php | 1 - 4 files changed, 20 insertions(+), 30 deletions(-) rename backport-changelog/{6.8 => 6.7}/7661.md (67%) delete mode 100644 lib/compat/wordpress-6.8/preload.php diff --git a/backport-changelog/6.8/7661.md b/backport-changelog/6.7/7661.md similarity index 67% rename from backport-changelog/6.8/7661.md rename to backport-changelog/6.7/7661.md index 2170f50c2a4e86..711d03595162ca 100644 --- a/backport-changelog/6.8/7661.md +++ b/backport-changelog/6.7/7661.md @@ -1,3 +1,4 @@ https://github.com/WordPress/wordpress-develop/pull/7661 * https://github.com/WordPress/gutenberg/pull/66468 +* https://github.com/WordPress/gutenberg/pull/66543 diff --git a/lib/compat/wordpress-6.7/rest-api.php b/lib/compat/wordpress-6.7/rest-api.php index 313367594caae0..89efdc4c4219d2 100644 --- a/lib/compat/wordpress-6.7/rest-api.php +++ b/lib/compat/wordpress-6.7/rest-api.php @@ -50,6 +50,25 @@ function gutenberg_block_editor_preload_paths_6_7( $paths, $context ) { } } + // Preload theme and global styles paths. + $excluded_paths = array(); + if ( 'core/edit-site' === $context->name || 'core/edit-post' === $context->name ) { + $active_theme = get_stylesheet(); + $global_styles_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id(); + $paths[] = '/wp/v2/global-styles/themes/' . $active_theme . '?context=view'; + $paths[] = '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view'; + $paths[] = array( '/wp/v2/global-styles/' . $global_styles_id, 'OPTIONS' ); + + // Remove duplicate or unnecessary global styles paths. + $excluded_paths[] = '/wp/v2/global-styles/themes/' . $active_theme; + $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id; + foreach ( $paths as $key => $path ) { + if ( in_array( $path, $excluded_paths, true ) ) { + unset( $paths[ $key ] ); + } + } + } + return $paths; } add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_7', 10, 2 ); diff --git a/lib/compat/wordpress-6.8/preload.php b/lib/compat/wordpress-6.8/preload.php deleted file mode 100644 index 057cdc0965757b..00000000000000 --- a/lib/compat/wordpress-6.8/preload.php +++ /dev/null @@ -1,29 +0,0 @@ -name || 'core/edit-post' === $context->name ) { - $stylesheet = get_stylesheet(); - $global_styles_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id(); - $paths[] = '/wp/v2/global-styles/themes/' . $stylesheet . '?context=view'; - $paths[] = '/wp/v2/global-styles/themes/' . $stylesheet . '/variations?context=view'; - $paths[] = array( '/wp/v2/global-styles/' . $global_styles_id, 'OPTIONS' ); - $excluded_paths[] = '/wp/v2/global-styles/themes/' . $stylesheet; - $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id; - } - foreach ( $paths as $key => $path ) { - if ( in_array( $path, $excluded_paths, true ) ) { - unset( $paths[ $key ] ); - } - } - return $paths; -} -add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_8', 10, 2 ); diff --git a/lib/load.php b/lib/load.php index 574d901e72a69c..2c8a0fd0347c92 100644 --- a/lib/load.php +++ b/lib/load.php @@ -47,7 +47,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.7/rest-api.php'; // WordPress 6.8 compat. - require __DIR__ . '/compat/wordpress-6.8/preload.php'; require __DIR__ . '/compat/wordpress-6.8/block-comments.php'; require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php';