From 6ec211aee9889be4b543f25f4a592d57b083c320 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 4 Mar 2025 21:03:31 +0400 Subject: [PATCH] Site Editor: Fix template lookup preloading for non-draft pages (#69400) Co-authored-by: Mamaduka --- backport-changelog/6.8/8441.md | 3 +++ lib/compat/wordpress-6.8/preload.php | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 backport-changelog/6.8/8441.md diff --git a/backport-changelog/6.8/8441.md b/backport-changelog/6.8/8441.md new file mode 100644 index 00000000000000..810d833594391d --- /dev/null +++ b/backport-changelog/6.8/8441.md @@ -0,0 +1,3 @@ +https://github.com/WordPress/wordpress-develop/pull/8441 + +* https://github.com/WordPress/gutenberg/pull/69400 diff --git a/lib/compat/wordpress-6.8/preload.php b/lib/compat/wordpress-6.8/preload.php index 6a0102f1848eae..4e6875bf9fb080 100644 --- a/lib/compat/wordpress-6.8/preload.php +++ b/lib/compat/wordpress-6.8/preload.php @@ -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' ); } @@ -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'; @@ -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 );