From 5225d192ac27762f37628244f3b70ba6f60defee Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 19 Oct 2026 21:50:48 +0100 Subject: [PATCH] Editor: Preload the entity fields of the post editor. The post summary of the post editor's inspector reads the fields of the edited post type from the `/wp/v2/entity-fields` route since Gutenberg stabilized the DataForm-based inspector, so the post editor now preloads them, as the site editor does. Follow-up to [64528]. See #66339. --- src/wp-includes/entity-fields.php | 27 +++++++++---------- .../entity-fields/wpPreloadEntityFields.php | 11 ++++---- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/entity-fields.php b/src/wp-includes/entity-fields.php index 91a0547557a3e..3f6a87039f9dd 100644 --- a/src/wp-includes/entity-fields.php +++ b/src/wp-includes/entity-fields.php @@ -323,16 +323,13 @@ function _wp_get_site_editor_screen_post_types() { } /** - * Preloads the fields of the post types the site editor lists. + * Preloads the fields of the post types the editors list. * - * The site editor reads them from the `/wp/v2/entity-fields` route before it - * can list the post fields, see `useFields` in - * packages/editor/src/dataviews/fields-loader/index.ts in Gutenberg: those of - * the edited post, if any, and of the post types of the screen it opens on. - * - * The post editor is left untouched: it only reads the fields in the - * DataForm-based inspector, an experiment of the Gutenberg plugin which - * preloads them on its own. + * The editors read them from the `/wp/v2/entity-fields` route, see `useFields` + * in packages/editor/src/dataviews/fields-loader/index.ts in Gutenberg. The + * post editor reads those of the edited post in the post summary of its + * inspector. The site editor reads those of the edited post, if any, and of + * the post types of the screen it opens on. * * @since 7.2.0 * @access private @@ -342,15 +339,15 @@ function _wp_get_site_editor_screen_post_types() { * @return array Filtered preload paths. */ function _wp_preload_entity_fields( $paths, $context ) { - if ( 'core/edit-site' !== $context->name ) { - return $paths; - } - $post_types = array(); - if ( isset( $context->post ) ) { + if ( 'core/edit-post' === $context->name && isset( $context->post ) ) { $post_types[] = $context->post->post_type; + } elseif ( 'core/edit-site' === $context->name ) { + if ( isset( $context->post ) ) { + $post_types[] = $context->post->post_type; + } + $post_types = array_merge( $post_types, _wp_get_site_editor_screen_post_types() ); } - $post_types = array_merge( $post_types, _wp_get_site_editor_screen_post_types() ); return array_merge( $paths, diff --git a/tests/phpunit/tests/entity-fields/wpPreloadEntityFields.php b/tests/phpunit/tests/entity-fields/wpPreloadEntityFields.php index 064fbbf063566..679de5edc5848 100644 --- a/tests/phpunit/tests/entity-fields/wpPreloadEntityFields.php +++ b/tests/phpunit/tests/entity-fields/wpPreloadEntityFields.php @@ -32,12 +32,13 @@ public function test_the_fields_are_preloaded_on_the_block_editor_preload_paths( } /** - * The post editor does not preload the fields, whatever its `p` query arg. + * The post editor preloads the fields of the edited post type, which the + * post summary of its inspector reads, whatever its `p` query arg. * - * @ticket 66229 + * @ticket 66339 */ - public function test_the_post_editor_does_not_preload_the_fields() { - $_GET['p'] = '/page'; + public function test_the_post_editor_preloads_the_fields_of_the_post_type() { + $_GET['p'] = '/wp_template'; $post = self::factory()->post->create_and_get( array( 'post_type' => 'page' ) ); $context = new WP_Block_Editor_Context( array( @@ -46,7 +47,7 @@ public function test_the_post_editor_does_not_preload_the_fields() { ) ); - $this->assertSame( array(), _wp_preload_entity_fields( array(), $context ) ); + $this->assertSame( array( '/wp/v2/entity-fields?kind=postType&name=page' ), _wp_preload_entity_fields( array(), $context ) ); } /**