Skip to content

Commit

Permalink
Sync with #66543
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Oct 30, 2024
1 parent 4dfc9bb commit a53ebf8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 43 deletions.
33 changes: 33 additions & 0 deletions lib/compat/wordpress-6.7/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
42 changes: 0 additions & 42 deletions lib/compat/wordpress-6.8/preload.php

This file was deleted.

1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit a53ebf8

Please sign in to comment.