Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/11948

* https://github.com/WordPress/gutenberg/pull/78565
* https://github.com/WordPress/gutenberg/pull/79359
28 changes: 0 additions & 28 deletions lib/compat/wordpress-7.0/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,3 @@ static function ( $path ) {
return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_9', 10, 2 );

/**
* Preload bound single-resource GETs the post editor would otherwise
* fetch post-mount.
*
* @param array $paths REST API paths.
* @param WP_Block_Editor_Context $context Block editor context.
* @return array
*/
function gutenberg_block_editor_preload_paths_post_editor_bound_gets( $paths, $context ) {
if ( 'core/edit-post' !== $context->name || ! isset( $context->post ) ) {
return $paths;
}
$paths[] = '/wp/v2/templates/lookup?slug=front-page';
$paths[] = '/wp/v2/taxonomies?context=edit';
$paths[] = array( '/wp/v2/posts', 'OPTIONS' );

$author_id = (int) get_post_field( 'post_author', $context->post->ID );
if ( $author_id ) {
$paths[] = sprintf(
'/wp/v2/users/%d?context=view&_fields=id,name',
$author_id
);
}

return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_post_editor_bound_gets', 10, 2 );
28 changes: 19 additions & 9 deletions lib/compat/wordpress-7.1/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
*/

/**
* Filters the block editor preload paths to include media processing fields.
*
* The packages/core-data/src/entities.js file requests additional fields
* (image_sizes, image_size_threshold) on the root endpoint that are not
* included in WordPress Core's default preload paths. This filter ensures
* the preloaded URL matches exactly what the JavaScript requests.
* Filters the block editor preload paths.
*
* @since 20.1.0
*
* @param array $paths REST API paths to preload.
* @param array $paths REST API paths to preload.
* @param WP_Block_Editor_Context $context Block editor context.
* @return array Filtered preload paths.
*/
function gutenberg_block_editor_preload_paths_root_fields( $paths ) {
function gutenberg_block_editor_preload_paths_7_1( $paths, $context ) {
// Complete list of fields expected by packages/core-data/src/entities.js.
// This must match exactly for preloading to work (same fields, same order).
// @see packages/core-data/src/entities.js rootEntitiesConfig.__unstableBase
Expand All @@ -32,6 +28,20 @@ function gutenberg_block_editor_preload_paths_root_fields( $paths ) {
}
}

if ( 'core/edit-post' === $context->name && isset( $context->post ) ) {
$paths[] = '/wp/v2/templates/lookup?slug=front-page';
$paths[] = '/wp/v2/taxonomies?context=edit';
$paths[] = array( rest_get_route_for_post_type_items( $context->post->post_type ), 'OPTIONS' );

$author_id = (int) get_post_field( 'post_author', $context->post->ID );
if ( post_type_supports( $context->post->post_type, 'author' ) && $author_id > 0 ) {
$paths[] = sprintf(
'/wp/v2/users/%d?context=view&_fields=id,name',
$author_id
);
}
}

return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_root_fields' );
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_7_1', 10, 2 );
Loading