Skip to content

Commit

Permalink
Editor: navigation post preloading.
Browse files Browse the repository at this point in the history
Adds a hook for preloading navigation posts in site editor.

Props get_dave, spacedmonkey, audrasjb, ramonopoly.
Fixes #58556.


git-svn-id: https://develop.svn.wordpress.org/trunk@56054 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
tellthemachines committed Jun 27, 2023
1 parent 7c4c4a8 commit 14a3070
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ static function( $classes ) {

$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
$active_theme = get_stylesheet();
$preload_paths = array(

$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',
'/wp/v2/types/wp_template?context=edit',
Expand All @@ -87,6 +92,37 @@ 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,
'order' => 'desc',
'orderby' => 'date',
'_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_paths[] = array(
add_query_arg(
array(
'context' => 'edit',
'per_page' => 100,
'order' => 'desc',
'orderby' => 'date',
'status[0]' => 'publish',
'status[1]' => 'draft',
),
$navigation_rest_route
),
'GET',
),
);

block_editor_rest_api_preload( $preload_paths, $block_editor_context );
Expand Down

0 comments on commit 14a3070

Please sign in to comment.