From a3eb0d803e9c3662b01302b15ae85f508cf5ab38 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Fri, 2 Oct 2020 17:45:49 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@49088 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-search-controller.php | 6 +++--- .../rest-api/search/class-wp-rest-search-handler.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php index b3e9db72b7..723c5f477b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php @@ -140,7 +140,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { ); } - $ids = array_map( 'absint', $result[ WP_REST_Search_Handler::RESULT_IDS ] ); + $ids = $result[ WP_REST_Search_Handler::RESULT_IDS ]; $results = array(); @@ -186,7 +186,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { * * @since 5.0.0 * - * @param int $id ID of the item to prepare. + * @param int|string $id ID of the item to prepare. * @param WP_REST_Request $request Request object. * @return WP_REST_Response Response object. */ @@ -245,7 +245,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller { 'properties' => array( self::PROP_ID => array( 'description' => __( 'Unique identifier for the object.' ), - 'type' => 'integer', + 'type' => array( 'integer', 'string' ), 'context' => array( 'view', 'embed' ), 'readonly' => true, ), diff --git a/src/wp-includes/rest-api/search/class-wp-rest-search-handler.php b/src/wp-includes/rest-api/search/class-wp-rest-search-handler.php index 4799e1c981..be2cc21b13 100644 --- a/src/wp-includes/rest-api/search/class-wp-rest-search-handler.php +++ b/src/wp-includes/rest-api/search/class-wp-rest-search-handler.php @@ -79,8 +79,8 @@ abstract class WP_REST_Search_Handler { * * @since 5.0.0 * - * @param int $id Item ID. - * @param array $fields Fields to include for the item. + * @param int|string $id Item ID. + * @param array $fields Fields to include for the item. * @return array Associative array containing all fields for the item. */ abstract public function prepare_item( $id, array $fields ); @@ -90,7 +90,7 @@ abstract class WP_REST_Search_Handler { * * @since 5.0.0 * - * @param int $id Item ID. + * @param int|string $id Item ID. * @return array Links for the given item. */ abstract public function prepare_item_links( $id );