PluginProbe
Gutenberg / 23.6.0
Gutenberg v23.6.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / compat / wordpress-7.1 / preload.php

preload.php in Gutenberg 23.6.0, at lib/compat/wordpress-7.1/preload.php

48 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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_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';
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