Skip to content

Commit

Permalink
Global styles: move preload paths filter to 6.7 (previously 6.8) (#66543
Browse files Browse the repository at this point in the history
)

* 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 <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
Co-authored-by: andrewserong <[email protected]>
  • Loading branch information
4 people authored Oct 29, 2024
1 parent 02da291 commit dc4bd05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 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,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 );
Expand Down
29 changes: 0 additions & 29 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 dc4bd05

Please sign in to comment.