PluginProbe
Gutenberg / 23.4.0
Gutenberg v23.4.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.4.0, at lib/compat/wordpress-7.1/preload.php

38 lines 1.4 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 to include media processing fields.
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 * @since 20.1.0
17 *
18 * @param array $paths REST API paths to preload.
19 * @return array Filtered preload paths.
20 */
21 function gutenberg_block_editor_preload_paths_root_fields( $paths ) {
22 // Complete list of fields expected by packages/core-data/src/entities.js.
23 // This must match exactly for preloading to work (same fields, same order).
24 // @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';
26
27 foreach ( $paths as $key => $path ) {
28 if ( is_string( $path ) && str_starts_with( $path, '/?_fields=' ) ) {
29 // Replace with the complete fields list to ensure exact match.
30 $paths[ $key ] = '/?_fields=' . $root_fields;
31 break;
32 }
33 }
34
35 return $paths;
36 }
37 add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_root_fields' );
38