--- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php Tue Dec 15 13:49:49 2020 +0100
@@ -68,9 +68,12 @@
foreach ( $search_handlers as $search_handler ) {
if ( ! $search_handler instanceof WP_REST_Search_Handler ) {
-
- /* translators: %s: PHP class name */
- _doing_it_wrong( __METHOD__, sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ), '5.0.0' );
+ _doing_it_wrong(
+ __METHOD__,
+ /* translators: %s: PHP class name. */
+ sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ),
+ '5.0.0'
+ );
continue;
}
@@ -130,12 +133,17 @@
$result = $handler->search_items( $request );
if ( ! isset( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! is_array( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! isset( $result[ WP_REST_Search_Handler::RESULT_TOTAL ] ) ) {
- return new WP_Error( 'rest_search_handler_error', __( 'Internal search handler error.' ), array( 'status' => 500 ) );
+ return new WP_Error(
+ 'rest_search_handler_error',
+ __( 'Internal search handler error.' ),
+ array( 'status' => 500 )
+ );
}
$ids = array_map( 'absint', $result[ WP_REST_Search_Handler::RESULT_IDS ] );
$results = array();
+
foreach ( $ids as $id ) {
$data = $this->prepare_item_for_response( $id, $request );
$results[] = $this->prepare_response_for_collection( $data );
@@ -147,7 +155,11 @@
$max_pages = ceil( $total / $per_page );
if ( $page > $max_pages && $total > 0 ) {
- return new WP_Error( 'rest_search_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
+ return new WP_Error(
+ 'rest_search_invalid_page_number',
+ __( 'The page number requested is larger than the number of pages available.' ),
+ array( 'status' => 400 )
+ );
}
$response = rest_ensure_response( $results );
@@ -211,8 +223,13 @@
* @return array Item schema data.
*/
public function get_item_schema() {
+ if ( $this->schema ) {
+ return $this->add_additional_fields_schema( $this->schema );
+ }
+
$types = array();
$subtypes = array();
+
foreach ( $this->search_handlers as $search_handler ) {
$types[] = $search_handler->get_type();
$subtypes = array_merge( $subtypes, $search_handler->get_subtypes() );
@@ -262,7 +279,9 @@
),
);
- return $this->add_additional_fields_schema( $schema );
+ $this->schema = $schema;
+
+ return $this->add_additional_fields_schema( $this->schema );
}
/**
@@ -275,6 +294,7 @@
public function get_collection_params() {
$types = array();
$subtypes = array();
+
foreach ( $this->search_handlers as $search_handler ) {
$types[] = $search_handler->get_type();
$subtypes = array_merge( $subtypes, $search_handler->get_subtypes() );
@@ -351,7 +371,11 @@
$type = $request->get_param( self::PROP_TYPE );
if ( ! $type || ! isset( $this->search_handlers[ $type ] ) ) {
- return new WP_Error( 'rest_search_invalid_type', __( 'Invalid type parameter.' ), array( 'status' => 400 ) );
+ return new WP_Error(
+ 'rest_search_invalid_type',
+ __( 'Invalid type parameter.' ),
+ array( 'status' => 400 )
+ );
}
return $this->search_handlers[ $type ];