Make WordPress Core

Changeset 49088


Ignore:
Timestamp:
10/02/2020 05:45:49 PM (4 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Allow for string ids in the search controller.

Previously, the search controller infrastructure required that the id property was an integer. This prevents data models that use a string id from utilizing the search infrastructure.

This commit lifts the restraint that search handlers return integer ids. This will allow for the Post Formats search handler coming in 5.6 to use slugs instead of creating fake ids.

Props stoyangeorgiev.
Fixes #51131.

Location:
trunk/src/wp-includes/rest-api
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php

    r47122 r49088  
    141141        }
    142142
    143         $ids = array_map( 'absint', $result[ WP_REST_Search_Handler::RESULT_IDS ] );
     143        $ids = $result[ WP_REST_Search_Handler::RESULT_IDS ];
    144144
    145145        $results = array();
     
    187187     * @since 5.0.0
    188188     *
    189      * @param int             $id      ID of the item to prepare.
     189     * @param int|string      $id      ID of the item to prepare.
    190190     * @param WP_REST_Request $request Request object.
    191191     * @return WP_REST_Response Response object.
     
    246246                self::PROP_ID      => array(
    247247                    'description' => __( 'Unique identifier for the object.' ),
    248                     'type'        => 'integer',
     248                    'type'        => array( 'integer', 'string' ),
    249249                    'context'     => array( 'view', 'embed' ),
    250250                    'readonly'    => true,
  • trunk/src/wp-includes/rest-api/search/class-wp-rest-search-handler.php

    r46586 r49088  
    8080     * @since 5.0.0
    8181     *
    82      * @param int  $id     Item ID.
    83      * @param array $fields Fields to include for the item.
     82     * @param int|string $id     Item ID.
     83     * @param array      $fields Fields to include for the item.
    8484     * @return array Associative array containing all fields for the item.
    8585     */
     
    9191     * @since 5.0.0
    9292     *
    93      * @param int $id Item ID.
     93     * @param int|string $id Item ID.
    9494     * @return array Links for the given item.
    9595     */
Note: See TracChangeset for help on using the changeset viewer.