diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index 3207bccdf2632..62229d8ed4db4 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -56,7 +56,16 @@ static function ( $classes ) { $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'] ) ) { + $post_id = (int) $_GET['postId']; + if ( $post_id ) { + $context_settings['post'] = get_post( $post_id ); + } +} + +$block_editor_context = new WP_Block_Editor_Context( $context_settings ); $custom_settings = array( 'siteUrl' => site_url(), 'postsPerPage' => get_option( 'posts_per_page' ), @@ -118,6 +127,24 @@ static function ( $classes ) { ), ); +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/489f6067c623926bce7151a76755bb68d8e22ea7/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js#L139-L140 + 'page-' . $block_editor_context->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(