equal
deleted
inserted
replaced
80 $this->search_handlers[ $search_handler->get_type() ] = $search_handler; |
80 $this->search_handlers[ $search_handler->get_type() ] = $search_handler; |
81 } |
81 } |
82 } |
82 } |
83 |
83 |
84 /** |
84 /** |
85 * Registers the routes for the objects of the controller. |
85 * Registers the routes for the search controller. |
86 * |
86 * |
87 * @since 5.0.0 |
87 * @since 5.0.0 |
88 * |
88 * |
89 * @see register_rest_route() |
89 * @see register_rest_route() |
90 */ |
90 */ |
138 __( 'Internal search handler error.' ), |
138 __( 'Internal search handler error.' ), |
139 array( 'status' => 500 ) |
139 array( 'status' => 500 ) |
140 ); |
140 ); |
141 } |
141 } |
142 |
142 |
143 $ids = array_map( 'absint', $result[ WP_REST_Search_Handler::RESULT_IDS ] ); |
143 $ids = $result[ WP_REST_Search_Handler::RESULT_IDS ]; |
144 |
144 |
145 $results = array(); |
145 $results = array(); |
146 |
146 |
147 foreach ( $ids as $id ) { |
147 foreach ( $ids as $id ) { |
148 $data = $this->prepare_item_for_response( $id, $request ); |
148 $data = $this->prepare_item_for_response( $id, $request ); |
183 |
183 |
184 /** |
184 /** |
185 * Prepares a single search result for response. |
185 * Prepares a single search result for response. |
186 * |
186 * |
187 * @since 5.0.0 |
187 * @since 5.0.0 |
188 * |
188 * @since 5.6.0 The `$id` parameter can accept a string. |
189 * @param int $id ID of the item to prepare. |
189 * |
|
190 * @param int|string $id ID of the item to prepare. |
190 * @param WP_REST_Request $request Request object. |
191 * @param WP_REST_Request $request Request object. |
191 * @return WP_REST_Response Response object. |
192 * @return WP_REST_Response Response object. |
192 */ |
193 */ |
193 public function prepare_item_for_response( $id, $request ) { |
194 public function prepare_item_for_response( $id, $request ) { |
194 $handler = $this->get_search_handler( $request ); |
195 $handler = $this->get_search_handler( $request ); |
243 'title' => 'search-result', |
244 'title' => 'search-result', |
244 'type' => 'object', |
245 'type' => 'object', |
245 'properties' => array( |
246 'properties' => array( |
246 self::PROP_ID => array( |
247 self::PROP_ID => array( |
247 'description' => __( 'Unique identifier for the object.' ), |
248 'description' => __( 'Unique identifier for the object.' ), |
248 'type' => 'integer', |
249 'type' => array( 'integer', 'string' ), |
249 'context' => array( 'view', 'embed' ), |
250 'context' => array( 'view', 'embed' ), |
250 'readonly' => true, |
251 'readonly' => true, |
251 ), |
252 ), |
252 self::PROP_TITLE => array( |
253 self::PROP_TITLE => array( |
253 'description' => __( 'The title for the object.' ), |
254 'description' => __( 'The title for the object.' ), |