Skip to content

Commit

Permalink
Move for loop into context block
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Oct 29, 2024
1 parent 9835f45 commit 4dfc9bb
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
$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 ] );
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";
// 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;
Expand Down

0 comments on commit 4dfc9bb

Please sign in to comment.