| @@ -5,25 +5,21 @@ | ||
| 5 | 5 | * @package gutenberg |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Filters the block editor preload paths to include media processing fields. | |
| 9 | + * Filters the block editor preload paths. | |
| 10 | 10 | * |
| 11 | - * The packages/core-data/src/entities.js file requests additional fields | |
| 12 | - * (image_sizes, image_size_threshold) on the root endpoint that are not | |
| 13 | - * included in WordPress Core's default preload paths. This filter ensures | |
| 14 | - * the preloaded URL matches exactly what the JavaScript requests. | |
| 15 | - * | |
| 16 | 11 | * @since 20.1.0 |
| 17 | 12 | * |
| 18 | - * @param array $paths REST API paths to preload. | |
| 13 | + * @param array $paths REST API paths to preload. | |
| 14 | + * @param WP_Block_Editor_Context $context Block editor context. | |
| 19 | 15 | * @return array Filtered preload paths. |
| 20 | 16 | */ |
| 21 | -function gutenberg_block_editor_preload_paths_root_fields( $paths ) { | |
| 17 | +function gutenberg_block_editor_preload_paths_7_1( $paths, $context ) { | |
| 22 | 18 | // Complete list of fields expected by packages/core-data/src/entities.js. |
| 23 | 19 | // This must match exactly for preloading to work (same fields, same order). |
| 24 | 20 | // @see packages/core-data/src/entities.js rootEntitiesConfig.__unstableBase |
| 25 | - $root_fields = 'description,gmt_offset,home,image_sizes,image_size_threshold,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front'; | |
| 21 | + $root_fields = 'description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front'; | |
| 26 | 22 | |
| 27 | 23 | foreach ( $paths as $key => $path ) { |
| 28 | 24 | if ( is_string( $path ) && str_starts_with( $path, '/?_fields=' ) ) { |
| 29 | 25 | // Replace with the complete fields list to ensure exact match. |
| @@ -31,7 +27,21 @@ | ||
| 31 | 27 | break; |
| 32 | 28 | } |
| 33 | 29 | } |
| 34 | 30 | |
| 31 | + if ( 'core/edit-post' === $context->name && isset( $context->post ) ) { | |
| 32 | + $paths[] = '/wp/v2/templates/lookup?slug=front-page'; | |
| 33 | + $paths[] = '/wp/v2/taxonomies?context=edit'; | |
| 34 | + $paths[] = array( rest_get_route_for_post_type_items( $context->post->post_type ), 'OPTIONS' ); | |
| 35 | + | |
| 36 | + $author_id = (int) get_post_field( 'post_author', $context->post->ID ); | |
| 37 | + if ( post_type_supports( $context->post->post_type, 'author' ) && $author_id > 0 ) { | |
| 38 | + $paths[] = sprintf( | |
| 39 | + '/wp/v2/users/%d?context=view&_fields=id,name', | |
| 40 | + $author_id | |
| 41 | + ); | |
| 42 | + } | |
| 43 | + } | |
| 44 | + | |
| 35 | 45 | return $paths; |
| 36 | 46 | } |
| 37 | -add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_root_fields' ); | |
| 47 | +add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_7_1', 10, 2 ); | |