| @@ -25,4 +25,35 @@ | ||
| 25 | 25 | |
| 26 | 26 | return $paths; |
| 27 | 27 | } |
| 28 | 28 | add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_9', 10, 2 ); |
| 29 | + | |
| 30 | +/** | |
| 31 | + * Filters the block editor preload paths to include media processing fields. | |
| 32 | + * | |
| 33 | + * The packages/core-data/src/entities.js file requests additional fields | |
| 34 | + * (image_sizes, image_size_threshold) on the root endpoint that are not | |
| 35 | + * included in WordPress Core's default preload paths. This filter ensures | |
| 36 | + * the preloaded URL matches exactly what the JavaScript requests. | |
| 37 | + * | |
| 38 | + * @since 20.1.0 | |
| 39 | + * | |
| 40 | + * @param array $paths REST API paths to preload. | |
| 41 | + * @return array Filtered preload paths. | |
| 42 | + */ | |
| 43 | +function gutenberg_block_editor_preload_paths_root_fields( $paths ) { | |
| 44 | + // Complete list of fields expected by packages/core-data/src/entities.js. | |
| 45 | + // This must match exactly for preloading to work (same fields, same order). | |
| 46 | + // @see packages/core-data/src/entities.js rootEntitiesConfig.__unstableBase | |
| 47 | + $root_fields = 'description,gmt_offset,home,image_sizes,image_size_threshold,image_output_formats,jpeg_interlaced,png_interlaced,gif_interlaced,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front'; | |
| 48 | + | |
| 49 | + foreach ( $paths as $key => $path ) { | |
| 50 | + if ( is_string( $path ) && str_starts_with( $path, '/?_fields=' ) ) { | |
| 51 | + // Replace with the complete fields list to ensure exact match. | |
| 52 | + $paths[ $key ] = '/?_fields=' . $root_fields; | |
| 53 | + break; | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + return $paths; | |
| 58 | +} | |
| 59 | +add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_root_fields' ); | |