--- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php Fri Sep 05 18:40:08 2025 +0200
@@ -152,7 +152,7 @@
$total = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ];
$page = (int) $request['page'];
$per_page = (int) $request['per_page'];
- $max_pages = ceil( $total / $per_page );
+ $max_pages = (int) ceil( $total / $per_page );
if ( $page > $max_pages && $total > 0 ) {
return new WP_Error(
@@ -195,6 +195,7 @@
public function prepare_item_for_response( $item, $request ) {
// Restores the more descriptive, specific name for use within this method.
$item_id = $item;
+
$handler = $this->get_search_handler( $request );
if ( is_wp_error( $handler ) ) {
return new WP_REST_Response();
@@ -210,11 +211,13 @@
$response = rest_ensure_response( $data );
- $links = $handler->prepare_item_links( $item_id );
- $links['collection'] = array(
- 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
- );
- $response->add_links( $links );
+ if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
+ $links = $handler->prepare_item_links( $item_id );
+ $links['collection'] = array(
+ 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
+ );
+ $response->add_links( $links );
+ }
return $response;
}
@@ -329,6 +332,24 @@
'sanitize_callback' => array( $this, 'sanitize_subtypes' ),
);
+ $query_params['exclude'] = array(
+ 'description' => __( 'Ensure result set excludes specific IDs.' ),
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'integer',
+ ),
+ 'default' => array(),
+ );
+
+ $query_params['include'] = array(
+ 'description' => __( 'Limit result set to specific IDs.' ),
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'integer',
+ ),
+ 'default' => array(),
+ );
+
return $query_params;
}
@@ -340,7 +361,7 @@
* @param string|array $subtypes One or more subtypes.
* @param WP_REST_Request $request Full details about the request.
* @param string $parameter Parameter name.
- * @return array|WP_Error List of valid subtypes, or WP_Error object on failure.
+ * @return string[]|WP_Error List of valid subtypes, or WP_Error object on failure.
*/
public function sanitize_subtypes( $subtypes, $request, $parameter ) {
$subtypes = wp_parse_slug_list( $subtypes );
@@ -374,7 +395,7 @@
protected function get_search_handler( $request ) {
$type = $request->get_param( self::PROP_TYPE );
- if ( ! $type || ! isset( $this->search_handlers[ $type ] ) ) {
+ if ( ! $type || ! is_string( $type ) || ! isset( $this->search_handlers[ $type ] ) ) {
return new WP_Error(
'rest_search_invalid_type',
__( 'Invalid type parameter.' ),