Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's verify that postId is an int value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$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' ),
Expand Down Expand Up @@ -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(
Expand Down