Skip to content

Commit

Permalink
Just handle everything in 6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Oct 29, 2024
1 parent ea05e45 commit 9835f45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/compat/wordpress-6.6/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ function gutenberg_register_wp_rest_post_types_controller_fields() {
*/
function gutenberg_block_editor_preload_paths_6_6( $paths, $context ) {
if ( 'core/edit-post' === $context->name ) {
$paths[] = '/wp/v2/global-styles/themes/' . get_stylesheet();
$paths[] = '/wp/v2/themes?context=edit&status=active';
$paths[] = '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id() . '?context=edit';
}
return $paths;
}
Expand Down
15 changes: 10 additions & 5 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
$paths[] = '/wp/v2/global-styles/themes/' . $stylesheet . '/variations?context=view';
$excluded_paths[] = '/wp/v2/global-styles/themes/' . $stylesheet;
$excluded_paths[] = '/wp/v2/global-styles/' . $global_styles_id;
}

if ( 'core/edit-post' === $context->name ) {
$context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
$paths[] = "/wp/v2/global-styles/$global_styles_id?context=$context";
// 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 ) {
Expand All @@ -31,6 +30,12 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
}
}

// 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 );

0 comments on commit 9835f45

Please sign in to comment.