diff --git a/lib/compat/wordpress-6.7/rest-api.php b/lib/compat/wordpress-6.7/rest-api.php index 313367594caae0..65d7fb9bf4313b 100644 --- a/lib/compat/wordpress-6.7/rest-api.php +++ b/lib/compat/wordpress-6.7/rest-api.php @@ -50,6 +50,39 @@ 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[] = array( '/wp/v2/global-styles/' . $global_styles_id, 'OPTIONS' ); + $paths[] = '/wp/v2/global-styles/themes/' . $active_theme . '?context=view'; + $paths[] = '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view'; + + // 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; + // Removes the edit context path originating Core's preload paths. + $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id . '?context=view'; + // Removes the edit context path originating from gutenberg_block_editor_preload_paths_6_6(). + $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id . '?context=edit'; + + // Remove excluded paths so they are not preloaded. + foreach ( $paths as $key => $path ) { + if ( in_array( $path, $excluded_paths, true ) ) { + unset( $paths[ $key ] ); + } + } + + /* + * Add the global styles path with the correct context based on user caps. + * The corresponding paths are removed above so their output is not rendered into the HTML + * unnecessarily. + */ + $context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view'; + $paths[] = "/wp/v2/global-styles/$global_styles_id?context=$context"; + } + 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 fb793b2cab9152..00000000000000 --- a/lib/compat/wordpress-6.8/preload.php +++ /dev/null @@ -1,42 +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[] = array( '/wp/v2/global-styles/' . $global_styles_id, 'OPTIONS' ); - $paths[] = '/wp/v2/global-styles/themes/' . $stylesheet . '?context=view'; - $paths[] = '/wp/v2/global-styles/themes/' . $stylesheet . '/variations?context=view'; - - // Remove duplicate or unnecessary global styles paths. - $excluded_paths[] = '/wp/v2/global-styles/themes/' . $stylesheet; - $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id; - // Removes the edit context path originating Core's preload paths. - $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id . '?context=view'; - // Removes the edit context path originating from gutenberg_block_editor_preload_paths_6_6(). - $excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id . '?context=edit'; - foreach ( $paths as $key => $path ) { - if ( in_array( $path, $excluded_paths, true ) ) { - unset( $paths[ $key ] ); - } - } - - // Add the global styles path with the correct context based on user caps. - if ( 'core/edit-site' === $context->name || 'core/edit-post' === $context->name ) { - $context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view'; - $paths[] = "/wp/v2/global-styles/$global_styles_id?context=$context"; - } - } - - 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';