Editor: Update preload paths for post and site editor.
Preloading all blocking requests ensures that the editor canvas becomes responsive quickly and that the browser avoids unnecessary client-side requests. Props mamaduka, joemcgill, audrasjb, peterwilsoncc. Fixes #63050. Built from https://develop.svn.wordpress.org/trunk@59958 git-svn-id: http://core.svn.wordpress.org/trunk@59300 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -53,6 +53,10 @@ $rest_path = rest_get_route_for_post( $post );
|
||||
|
||||
$active_theme = get_stylesheet();
|
||||
$global_styles_endpoint_context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
|
||||
$template_lookup_slug = 'page' === $post->post_type ? 'page' : 'single-' . $post->post_type;
|
||||
if ( ! empty( $post->post_name ) ) {
|
||||
$template_lookup_slug .= '-' . $post->post_name;
|
||||
}
|
||||
// Preload common data.
|
||||
$preload_paths = array(
|
||||
'/wp/v2/types?context=view',
|
||||
@@ -79,6 +83,32 @@ $preload_paths = array(
|
||||
* Please ensure that the equivalent check is kept in sync with this preload path.
|
||||
*/
|
||||
'/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=' . $global_styles_endpoint_context,
|
||||
// Used by getBlockPatternCategories in useBlockEditorSettings.
|
||||
'/wp/v2/block-patterns/categories',
|
||||
// @see packages/core-data/src/entities.js
|
||||
'/?_fields=' . implode(
|
||||
',',
|
||||
array(
|
||||
'description',
|
||||
'gmt_offset',
|
||||
'home',
|
||||
'name',
|
||||
'site_icon',
|
||||
'site_icon_url',
|
||||
'site_logo',
|
||||
'timezone_string',
|
||||
'url',
|
||||
'page_for_posts',
|
||||
'page_on_front',
|
||||
'show_on_front',
|
||||
)
|
||||
),
|
||||
$paths[] = add_query_arg(
|
||||
'slug',
|
||||
// @see https://github.com/WordPress/gutenberg/blob/e093fefd041eb6cc4a4e7f67b92ab54fd75c8858/packages/core-data/src/private-selectors.ts#L244-L254
|
||||
$template_lookup_slug,
|
||||
'/wp/v2/templates/lookup'
|
||||
),
|
||||
);
|
||||
|
||||
block_editor_rest_api_preload( $preload_paths, $block_editor_context );
|
||||
|
||||
@@ -139,7 +139,15 @@ foreach ( get_default_block_template_types() as $slug => $template_type ) {
|
||||
$indexed_template_types[] = $template_type;
|
||||
}
|
||||
|
||||
$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
|
||||
$context_settings = array( 'name' => 'core/edit-site' );
|
||||
|
||||
if ( ! empty( $_GET['postId'] ) && is_numeric( $_GET['postId'] ) ) {
|
||||
$context_settings['post'] = get_post( (int) $_GET['postId'] );
|
||||
} elseif ( isset( $_GET['p'] ) && preg_match( '/^\/page\/(\d+)$/', $_GET['p'], $matches ) ) {
|
||||
$context_settings['post'] = get_post( (int) $matches[1] );
|
||||
}
|
||||
|
||||
$block_editor_context = new WP_Block_Editor_Context( $context_settings );
|
||||
$custom_settings = array(
|
||||
'siteUrl' => site_url(),
|
||||
'postsPerPage' => get_option( 'posts_per_page' ),
|
||||
@@ -199,8 +207,48 @@ $preload_paths = array(
|
||||
),
|
||||
'GET',
|
||||
),
|
||||
'/wp/v2/settings',
|
||||
array( '/wp/v2/settings', 'OPTIONS' ),
|
||||
// Used by getBlockPatternCategories in useBlockEditorSettings.
|
||||
'/wp/v2/block-patterns/categories',
|
||||
// @see packages/core-data/src/entities.js
|
||||
'/?_fields=' . implode(
|
||||
',',
|
||||
array(
|
||||
'description',
|
||||
'gmt_offset',
|
||||
'home',
|
||||
'name',
|
||||
'site_icon',
|
||||
'site_icon_url',
|
||||
'site_logo',
|
||||
'timezone_string',
|
||||
'url',
|
||||
'page_for_posts',
|
||||
'page_on_front',
|
||||
'show_on_front',
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
if ( $block_editor_context->post ) {
|
||||
$route_for_post = rest_get_route_for_post( $block_editor_context->post );
|
||||
if ( $route_for_post ) {
|
||||
$preload_paths[] = add_query_arg( 'context', 'edit', $route_for_post );
|
||||
if ( 'page' === $block_editor_context->post->post_type ) {
|
||||
$preload_paths[] = add_query_arg(
|
||||
'slug',
|
||||
// @see https://github.com/WordPress/gutenberg/blob/e093fefd041eb6cc4a4e7f67b92ab54fd75c8858/packages/core-data/src/private-selectors.ts#L244-L254
|
||||
empty( $block_editor_context->post->post_name ) ? 'page' : 'page-' . $post->post_name,
|
||||
'/wp/v2/templates/lookup'
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$preload_paths[] = '/wp/v2/templates/lookup?slug=front-page';
|
||||
$preload_paths[] = '/wp/v2/templates/lookup?slug=home';
|
||||
}
|
||||
|
||||
block_editor_rest_api_preload( $preload_paths, $block_editor_context );
|
||||
|
||||
wp_add_inline_script(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.8-beta1-59957';
|
||||
$wp_version = '6.8-beta1-59958';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user