From 53b54895f35f05487252626286121f95c0c988f8 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 16 Jun 2023 13:37:24 +0100 Subject: [PATCH 1/5] Add new navigation file and backport the preloading hook --- src/wp-includes/navigation.php | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/wp-includes/navigation.php diff --git a/src/wp-includes/navigation.php b/src/wp-includes/navigation.php new file mode 100644 index 0000000000000..f249288f9da3e --- /dev/null +++ b/src/wp-includes/navigation.php @@ -0,0 +1,62 @@ +name ) && 'core/edit-site' !== $context->name ) { + return $preload_paths; + } + + $navigation_rest_route = rest_get_route_for_post_type_items( + 'wp_navigation' + ); + + // Preload the OPTIONS request for all Navigation posts request. + $preload_paths[] = array( $navigation_rest_route, 'OPTIONS' ); + + // Preload the GET request for ALL 'published' or 'draft' Navigation posts. + $preload_paths[] = array( + add_query_arg( + array( + 'context' => 'edit', + 'per_page' => 100, + '_locale' => 'user', + // array indices are required to avoid query being encoded and not matching in cache. + 'status[0]' => 'publish', + 'status[1]' => 'draft', + ), + $navigation_rest_route + ), + 'GET', + ); + + // Preload request for all menus in Browse Mode sidebar "Navigation" section. + $preload_paths[] = array( + add_query_arg( + array( + 'context' => 'edit', + 'per_page' => 100, + 'order' => 'desc', + 'orderby' => 'date', + 'status' => 'publish', + ), + $navigation_rest_route + ), + 'GET', + ); + + return $preload_paths; +} +add_filter( 'block_editor_rest_api_preload_paths', 'wp_preload_navigation_posts', 10, 2 ); From 27a3083731bb033db319df6293797a032f19ace0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:01:27 +0100 Subject: [PATCH 2/5] Inline preload paths for Navigation posts --- src/wp-admin/site-editor.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 9302c42389c66..925234eaea7a3 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -76,6 +76,11 @@ static function( $classes ) { $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); $active_theme = get_stylesheet(); + +$navigation_rest_route = rest_get_route_for_post_type_items( + 'wp_navigation' +); + $preload_paths = array( array( '/wp/v2/media', 'OPTIONS' ), '/wp/v2/types?context=view', @@ -87,6 +92,35 @@ static function( $classes ) { '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', '/wp/v2/global-styles/' . $active_global_styles_id, '/wp/v2/global-styles/themes/' . $active_theme, + array( $navigation_rest_route, 'OPTIONS' ), + array( + add_query_arg( + array( + 'context' => 'edit', + 'per_page' => 100, + '_locale' => 'user', + // array indices are required to avoid query being encoded and not matching + // caching in block editor. + 'status[0]' => 'publish', + 'status[1]' => 'draft', + ), + $navigation_rest_route + ), + 'GET', + ), + $preload_paths[] = array( + add_query_arg( + array( + 'context' => 'edit', + 'per_page' => 100, + 'order' => 'desc', + 'orderby' => 'date', + 'status' => 'publish', + ), + $navigation_rest_route + ), + 'GET', + ) ); block_editor_rest_api_preload( $preload_paths, $block_editor_context ); From a9880d2b4f615e1205cc1de7dc07f6270ea3fc9c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:01:41 +0100 Subject: [PATCH 3/5] Revert "Add new navigation file and backport the preloading hook" This reverts commit 53b54895f35f05487252626286121f95c0c988f8. --- src/wp-includes/navigation.php | 62 ---------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/wp-includes/navigation.php diff --git a/src/wp-includes/navigation.php b/src/wp-includes/navigation.php deleted file mode 100644 index f249288f9da3e..0000000000000 --- a/src/wp-includes/navigation.php +++ /dev/null @@ -1,62 +0,0 @@ -name ) && 'core/edit-site' !== $context->name ) { - return $preload_paths; - } - - $navigation_rest_route = rest_get_route_for_post_type_items( - 'wp_navigation' - ); - - // Preload the OPTIONS request for all Navigation posts request. - $preload_paths[] = array( $navigation_rest_route, 'OPTIONS' ); - - // Preload the GET request for ALL 'published' or 'draft' Navigation posts. - $preload_paths[] = array( - add_query_arg( - array( - 'context' => 'edit', - 'per_page' => 100, - '_locale' => 'user', - // array indices are required to avoid query being encoded and not matching in cache. - 'status[0]' => 'publish', - 'status[1]' => 'draft', - ), - $navigation_rest_route - ), - 'GET', - ); - - // Preload request for all menus in Browse Mode sidebar "Navigation" section. - $preload_paths[] = array( - add_query_arg( - array( - 'context' => 'edit', - 'per_page' => 100, - 'order' => 'desc', - 'orderby' => 'date', - 'status' => 'publish', - ), - $navigation_rest_route - ), - 'GET', - ); - - return $preload_paths; -} -add_filter( 'block_editor_rest_api_preload_paths', 'wp_preload_navigation_posts', 10, 2 ); From f8b44fa7260fbb6fc278ecb23ee89d1bd51a8416 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 21 Jun 2023 10:03:00 +0100 Subject: [PATCH 4/5] PHPCS --- src/wp-admin/site-editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 925234eaea7a3..ea5e425add6ff 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -81,7 +81,7 @@ static function( $classes ) { 'wp_navigation' ); -$preload_paths = array( +$preload_paths = array( array( '/wp/v2/media', 'OPTIONS' ), '/wp/v2/types?context=view', '/wp/v2/types/wp_template?context=edit', @@ -120,7 +120,7 @@ static function( $classes ) { $navigation_rest_route ), 'GET', - ) + ), ); block_editor_rest_api_preload( $preload_paths, $block_editor_context ); From 0118658f101d1927ece1c504bc9ca1c6cd924f3c Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 22 Jun 2023 13:25:19 +0100 Subject: [PATCH 5/5] Update to match new args --- src/wp-admin/site-editor.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index ea5e425add6ff..088103937f375 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -98,9 +98,10 @@ static function( $classes ) { array( 'context' => 'edit', 'per_page' => 100, + 'order' => 'desc', + 'orderby' => 'date', '_locale' => 'user', - // array indices are required to avoid query being encoded and not matching - // caching in block editor. + // array indices are required to avoid query being encoded and not matching in cache. 'status[0]' => 'publish', 'status[1]' => 'draft', ), @@ -111,11 +112,12 @@ static function( $classes ) { $preload_paths[] = array( add_query_arg( array( - 'context' => 'edit', - 'per_page' => 100, - 'order' => 'desc', - 'orderby' => 'date', - 'status' => 'publish', + 'context' => 'edit', + 'per_page' => 100, + 'order' => 'desc', + 'orderby' => 'date', + 'status[0]' => 'publish', + 'status[1]' => 'draft', ), $navigation_rest_route ),