From 90b878032cc2c5c39601a7c3e6e2615e2dc6cce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Thu, 30 Jul 2026 12:13:32 +0200 Subject: [PATCH] REST API: remove `search` and `page` from the view config schema. `search` and `page` are managed via the URL, which is their only source of truth, so they should not be persisted as part of a view configuration. Removes both properties from the shared ViewBase schema in `WP_REST_View_Config_Controller`, updates the `WP_View_Config_Data` docblock example that used `search`, and adds a test asserting neither property is declared by any view in the item schema. --- src/wp-includes/class-wp-view-config-data.php | 4 +-- .../class-wp-rest-view-config-controller.php | 9 +++---- .../rest-api/rest-view-config-controller.php | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-view-config-data.php b/src/wp-includes/class-wp-view-config-data.php index 8c3d255fab82d..adebb51f7b267 100644 --- a/src/wp-includes/class-wp-view-config-data.php +++ b/src/wp-includes/class-wp-view-config-data.php @@ -353,13 +353,13 @@ public function replace( array $patch, int $version ) { * * ```php * array( - * 'default_view' => array( 'search' => 'new search', 'fields' => array( 'newField' ) ), + * 'default_view' => array( 'titleField' => 'newTitleField', 'fields' => array( 'newField' ) ), * 'default_layouts' => array( 'grid' => array( 'layout' => array( 'badgeFields' => array( 'newField' ) ) ) ), * 'view_list' => array( array( 'slug' => 'table', 'title' => 'New title' ) ), * ) * ``` * - * - default_view will be updated so the search string is 'new search' and the newField is appended to the list of fields. + * - default_view will be updated so the titleField is 'newTitleField' and the newField is appended to the list of fields. * - default_layouts will be updated so that newField is appended to the badgeFields. * - view_list will be updated so that the view with slug 'table' has its title changed to 'New title'. * diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php index 34cd1572526c6..2b08a0b4f651a 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php @@ -391,15 +391,15 @@ public function get_item_schema() { /** * Returns the schema properties shared by all view types (ViewBase), excluding 'type'. * + * Note that `search` and `page` are not part of the schema: they are managed + * via the URL, which is their only source of truth. + * * @since 7.1.0 * * @return array Schema properties for the base view configuration. */ protected function get_view_base_schema() { return array( - 'search' => array( - 'type' => 'string', - ), 'filters' => array( 'type' => 'array', 'items' => array( @@ -444,9 +444,6 @@ protected function get_view_base_schema() { ), ), ), - 'page' => array( - 'type' => 'integer', - ), 'perPage' => array( 'type' => 'integer', ), diff --git a/tests/phpunit/tests/rest-api/rest-view-config-controller.php b/tests/phpunit/tests/rest-api/rest-view-config-controller.php index 9bfbdd67c7021..34fcd55e2466d 100644 --- a/tests/phpunit/tests/rest-api/rest-view-config-controller.php +++ b/tests/phpunit/tests/rest-api/rest-view-config-controller.php @@ -385,4 +385,29 @@ public function test_get_item_schema() { array_keys( $schema['properties'] ) ); } + + /** + * `search` and `page` are not part of the view schema: they are managed via + * the URL, which is their only source of truth. + * + * @covers ::get_item_schema + */ + public function test_get_item_schema_excludes_url_managed_view_properties() { + $controller = new WP_REST_View_Config_Controller(); + $schema = $controller->get_item_schema(); + + $views = array( + 'default_view' => $schema['properties']['default_view']['properties'], + 'view_list item view' => $schema['properties']['view_list']['items']['properties']['view']['properties'], + 'default_layouts.table' => $schema['properties']['default_layouts']['properties']['table']['properties'], + 'default_layouts.grid' => $schema['properties']['default_layouts']['properties']['grid']['properties'], + 'default_layouts.list' => $schema['properties']['default_layouts']['properties']['list']['properties'], + 'default_layouts.activity' => $schema['properties']['default_layouts']['properties']['activity']['properties'], + ); + + foreach ( $views as $label => $properties ) { + $this->assertArrayNotHasKey( 'search', $properties, "$label should not declare a `search` property." ); + $this->assertArrayNotHasKey( 'page', $properties, "$label should not declare a `page` property." ); + } + } }