From e9b5b1a5bc867f24f9193650983f60156dfbda09 Mon Sep 17 00:00:00 2001 From: TimothyBlynJacobs Date: Fri, 2 Oct 2020 17:47:09 +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. Built from https://develop.svn.wordpress.org/trunk@49088 git-svn-id: http://core.svn.wordpress.org/trunk@48850 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../rest-api/endpoints/class-wp-rest-search-controller.php | 6 +++--- .../rest-api/search/class-wp-rest-search-handler.php | 6 +++--- wp-includes/version.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php index b3e9db72b7..723c5f477b 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php +++ b/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/wp-includes/rest-api/search/class-wp-rest-search-handler.php b/wp-includes/rest-api/search/class-wp-rest-search-handler.php index 4799e1c981..be2cc21b13 100644 --- a/wp-includes/rest-api/search/class-wp-rest-search-handler.php +++ b/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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index b8812a2fbe..3b02eedcee 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-49087'; +$wp_version = '5.6-alpha-49088'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.