Skip to content

Commit

Permalink
Site Editor: Fix template lookup preloading for non-draft pages (#69400)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
Mamaduka and Mamaduka authored Mar 4, 2025
1 parent e093fef commit 6ec211a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions backport-changelog/6.8/8441.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/8441

* https://github.com/WordPress/gutenberg/pull/69400
9 changes: 5 additions & 4 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
if ( 'page' === $post->post_type ) {
$paths[] = add_query_arg(
'slug',
// @see https://github.com/WordPress/gutenberg/blob/489f6067c623926bce7151a76755bb68d8e22ea7/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js#L139-L140
'page-' . $post->post_name,
// @see https://github.com/WordPress/gutenberg/blob/e093fefd041eb6cc4a4e7f67b92ab54fd75c8858/packages/core-data/src/private-selectors.ts#L244-L254
empty( $post->post_name ) ? 'page' : 'page-' . $post->post_name,
'/wp/v2/templates/lookup'
);
}
Expand Down Expand Up @@ -68,8 +68,8 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
* See the call to `canUser()`, under `useGlobalStylesUserConfig()` in `packages/edit-site/src/components/use-global-styles-user-config/index.js`.
* Please ensure that the equivalent check is kept in sync with this preload path.
*/
$context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
$paths[] = "/wp/v2/global-styles/$global_styles_id?context=$context";
$rest_context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
$paths[] = "/wp/v2/global-styles/$global_styles_id?context=$rest_context";

// Used by getBlockPatternCategories in useBlockEditorSettings.
$paths[] = '/wp/v2/block-patterns/categories';
Expand All @@ -94,6 +94,7 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
)
);
}

return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_8', 10, 2 );

0 comments on commit 6ec211a

Please sign in to comment.