Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize preload paths only for core/edit-post page #40587

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 10 additions & 3 deletions lib/compat/wordpress-6.0/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
/**
* Optimizes the preload paths registered in Core (`edit-form-blocks.php`).
*
* @param array $preload_paths Preload paths to be filtered.
* @param array $preload_paths Preload paths to be filtered.
* @param WP_Block_Editor_Context $block_editor_context The current block editor context.
*
* @return array
*/
function gutenberg_optimize_preload_paths( $preload_paths ) {
function gutenberg_optimize_preload_paths( $preload_paths, $block_editor_context ) {
// optimize only the post editor page, not site or widgets.
if ( 'core/edit-post' !== $block_editor_context->name ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( 'core/edit-post' !== $block_editor_context->name ) {
if ( isset( $block_editor_context->name ) && 'core/edit-post' !== $block_editor_context->name ) {

The name property doesn't exist in WP >= 5.9, need to include a check to avoid PHP notice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the min requirement 5.9 now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's WP 6.0, so I don't think we need these changes anymore. See my previous comment - #40587 (comment).

return $preload_paths;
}

// remove preload of the `/` route.
$root_index = array_search( '/', $preload_paths, true );
if ( false !== $root_index ) {
Expand Down Expand Up @@ -48,7 +55,7 @@ function gutenberg_optimize_preload_paths( $preload_paths ) {

return $preload_paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_optimize_preload_paths' );
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_optimize_preload_paths', 10, 2 );

/**
* Disables loading remote block patterns from REST while initializing the editor.
Expand Down