| 1 |
<?php |
| 2 |
/** |
| 3 |
* Preload paths for client-side media processing. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Filters the block editor preload paths. |
| 10 |
* |
| 11 |
* @since 20.1.0 |
| 12 |
* |
| 13 |
* @param array $paths REST API paths to preload. |
| 14 |
* @param WP_Block_Editor_Context $context Block editor context. |
| 15 |
* @return array Filtered preload paths. |
| 16 |
*/ |
| 17 |
function gutenberg_block_editor_preload_paths_7_1( $paths, $context ) { |
| 18 |
// Complete list of fields expected by packages/core-data/src/entities.js. |
| 19 |
// This must match exactly for preloading to work (same fields, same order). |
| 20 |
// @see packages/core-data/src/entities.js rootEntitiesConfig.__unstableBase |
| 21 |
$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'; |
| 22 |
|
| 23 |
foreach ( $paths as $key => $path ) { |
| 24 |
if ( is_string( $path ) && str_starts_with( $path, '/?_fields=' ) ) { |
| 25 |
// Replace with the complete fields list to ensure exact match. |
| 26 |
$paths[ $key ] = '/?_fields=' . $root_fields; |
| 27 |
break; |
| 28 |
} |
| 29 |
} |
| 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 |
|
| 45 |
return $paths; |
| 46 |
} |
| 47 |
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_7_1', 10, 2 ); |
| 48 |
|