Make WordPress Core

Changeset 62973


Ignore:
Timestamp:
08/03/2026 02:20:36 PM (15 hours ago)
Author:
oandregal
Message:

View config REST Endpoint: remove search and page.

The search and page parameters source of truth is the URL,
and cannot be configured via the filters.

Props oandregal, ntsekouras, jorgefilipecosta.
Fixes #65577.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-view-config-data.php

    r62970 r62973  
    356356         * ```php
    357357         * array(
    358          *   'default_view' => array( 'search' => 'new search', 'fields' => array( 'newField' ) ),
     358         *   'default_view' => array( 'titleField' => 'newTitleField', 'fields' => array( 'newField' ) ),
    359359         *   'default_layouts' => array( 'grid' => array( 'layout' => array( 'badgeFields' => array( 'newField' ) ) ) ),
    360360         *   'view_list' => array( array( 'slug' => 'table', 'title' => 'New title' ) ),
     
    362362         * ```
    363363         *
    364          * - default_view will be updated so the search string is 'new search' and the newField is appended to the list of fields.
     364         * - default_view will be updated so the titleField is 'newTitleField' and the newField is appended to the list of fields.
    365365         * - default_layouts will be updated so that newField is appended to the badgeFields.
    366366         * - view_list will be updated so that the view with slug 'table' has its title changed to 'New title'.
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php

    r62949 r62973  
    392392         * Returns the schema properties shared by all view types (ViewBase), excluding 'type'.
    393393         *
     394         * Note that `search` and `page` are not part of the schema: they are managed
     395         * via the URL, which is their only source of truth.
     396         *
    394397         * @since 7.1.0
    395398         *
     
    398401        protected function get_view_base_schema() {
    399402                return array(
    400                         'search'                => array(
    401                                 'type' => 'string',
    402                         ),
    403403                        'filters'               => array(
    404404                                'type'  => 'array',
     
    444444                                        ),
    445445                                ),
    446                         ),
    447                         'page'                  => array(
    448                                 'type' => 'integer',
    449446                        ),
    450447                        'perPage'               => array(
  • trunk/tests/phpunit/tests/rest-api/rest-view-config-controller.php

    r62825 r62973  
    386386                );
    387387        }
     388
     389        /**
     390         * `search` and `page` are not part of the view schema: they are managed via
     391         * the URL, which is their only source of truth.
     392         *
     393         * @covers ::get_item_schema
     394         */
     395        public function test_get_item_schema_excludes_url_managed_view_properties() {
     396                $controller = new WP_REST_View_Config_Controller();
     397                $schema     = $controller->get_item_schema();
     398
     399                $views = array(
     400                        'default_view'             => $schema['properties']['default_view']['properties'],
     401                        'view_list item view'      => $schema['properties']['view_list']['items']['properties']['view']['properties'],
     402                        'default_layouts.table'    => $schema['properties']['default_layouts']['properties']['table']['properties'],
     403                        'default_layouts.grid'     => $schema['properties']['default_layouts']['properties']['grid']['properties'],
     404                        'default_layouts.list'     => $schema['properties']['default_layouts']['properties']['list']['properties'],
     405                        'default_layouts.activity' => $schema['properties']['default_layouts']['properties']['activity']['properties'],
     406                );
     407
     408                foreach ( $views as $label => $properties ) {
     409                        $this->assertArrayNotHasKey( 'search', $properties, "$label should not declare a `search` property." );
     410                        $this->assertArrayNotHasKey( 'page', $properties, "$label should not declare a `page` property." );
     411                }
     412        }
    388413}
Note: See TracChangeset for help on using the changeset viewer.