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 2170f50c2a4e8..711d03595162c 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 313367594caae..89efdc4c4219d 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 057cdc0965757..0000000000000 --- 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 574d901e72a69..2c8a0fd0347c9 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';