-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Edit Post: Preload the remaining REST requests the editor fires on load #78565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/11948 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/78565 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,3 +57,31 @@ function gutenberg_block_editor_preload_paths_root_fields( $paths ) { | |
| return $paths; | ||
| } | ||
| add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_root_fields' ); | ||
|
|
||
| /** | ||
| * Preload bound single-resource GETs the post editor would otherwise | ||
| * fetch post-mount. | ||
| * | ||
| * @param array $paths REST API paths. | ||
| * @param WP_Block_Editor_Context $context Block editor context. | ||
| * @return array | ||
| */ | ||
| function gutenberg_block_editor_preload_paths_post_editor_bound_gets( $paths, $context ) { | ||
| if ( 'core/edit-post' !== $context->name || ! isset( $context->post ) ) { | ||
| return $paths; | ||
| } | ||
| $paths[] = '/wp/v2/templates/lookup?slug=front-page'; | ||
| $paths[] = '/wp/v2/taxonomies?context=edit'; | ||
| $paths[] = array( '/wp/v2/posts', 'OPTIONS' ); | ||
|
|
||
| $author_id = (int) get_post_field( 'post_author', $context->post->ID ); | ||
| if ( $author_id ) { | ||
| $paths[] = sprintf( | ||
| '/wp/v2/users/%d?context=view&_fields=id,name', | ||
| $author_id | ||
| ); | ||
| } | ||
|
Comment on lines
+74
to
+83
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the options request should be made for the current post type, and we should use We should also check if the post type supports the author. IIRC, this request is made by the Post Author component, which isn't rendered when not supported. Screenshot from Patterns post editor
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the follow-up - #79359. |
||
|
|
||
| return $paths; | ||
| } | ||
| add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_post_editor_bound_gets', 10, 2 ); | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in the WP 7.1 directory.