REST API: Introduce controller for searching across post types.
Introduces a `WP_REST_Search_Controller` class which registers a `/wp/v2/search` endpoint. Search types are handled by extending `WP_REST_Search_Handler`. The default search type is `WP_REST_Post_Search_Handler` but can be filtered by plugins or a theme. Merges [43739,43741] from the 5.0 branch to trunk. Props danielbachhuber, flixos90, pento, rmccue, joehoyle. Fixes #39965. Built from https://develop.svn.wordpress.org/trunk@44107 git-svn-id: http://core.svn.wordpress.org/trunk@43937 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -230,6 +230,20 @@ function create_initial_rest_routes() {
|
||||
$controller = new WP_REST_Comments_Controller;
|
||||
$controller->register_routes();
|
||||
|
||||
/**
|
||||
* Filters the search handlers to use in the REST search controller.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param array $search_handlers List of search handlers to use in the controller. Each search
|
||||
* handler instance must extend the `WP_REST_Search_Handler` class.
|
||||
* Default is only a handler for posts.
|
||||
*/
|
||||
$search_handlers = apply_filters( 'wp_rest_search_handlers', array( new WP_REST_Post_Search_Handler() ) );
|
||||
|
||||
$controller = new WP_REST_Search_Controller( $search_handlers );
|
||||
$controller->register_routes();
|
||||
|
||||
// Settings.
|
||||
$controller = new WP_REST_Settings_Controller;
|
||||
$controller->register_routes();
|
||||
|
||||
Reference in New Issue
Block a user