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
This commit is contained in:
parent
f426a1fa04
commit
e9b5b1a5bc
|
@ -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();
|
$results = array();
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @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.
|
* @param WP_REST_Request $request Request object.
|
||||||
* @return WP_REST_Response Response object.
|
* @return WP_REST_Response Response object.
|
||||||
*/
|
*/
|
||||||
|
@ -245,7 +245,7 @@ class WP_REST_Search_Controller extends WP_REST_Controller {
|
||||||
'properties' => array(
|
'properties' => array(
|
||||||
self::PROP_ID => array(
|
self::PROP_ID => array(
|
||||||
'description' => __( 'Unique identifier for the object.' ),
|
'description' => __( 'Unique identifier for the object.' ),
|
||||||
'type' => 'integer',
|
'type' => array( 'integer', 'string' ),
|
||||||
'context' => array( 'view', 'embed' ),
|
'context' => array( 'view', 'embed' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
),
|
),
|
||||||
|
|
|
@ -79,8 +79,8 @@ abstract class WP_REST_Search_Handler {
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param int $id Item ID.
|
* @param int|string $id Item ID.
|
||||||
* @param array $fields Fields to include for the item.
|
* @param array $fields Fields to include for the item.
|
||||||
* @return array Associative array containing all fields for the item.
|
* @return array Associative array containing all fields for the item.
|
||||||
*/
|
*/
|
||||||
abstract public function prepare_item( $id, array $fields );
|
abstract public function prepare_item( $id, array $fields );
|
||||||
|
@ -90,7 +90,7 @@ abstract class WP_REST_Search_Handler {
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param int $id Item ID.
|
* @param int|string $id Item ID.
|
||||||
* @return array Links for the given item.
|
* @return array Links for the given item.
|
||||||
*/
|
*/
|
||||||
abstract public function prepare_item_links( $id );
|
abstract public function prepare_item_links( $id );
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue