WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/17/2018 05:02:04 PM (10 months ago)
Author:
danielbachhuber
Message:

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.

Props danielbachhuber, flixos90, pento, rmccue.
Fixes #39965.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api.php

    r43734 r43739  
    229229    // Comments.
    230230    $controller = new WP_REST_Comments_Controller;
     231    $controller->register_routes();
     232
     233    /**
     234     * Filters the search handlers to use in the REST search controller.
     235     *
     236     * @since 5.0.0
     237     *
     238     * @param array $search_handlers List of search handlers to use in the controller. Each search
     239     *                               handler instance must extend the `WP_REST_Search_Handler` class.
     240     *                               Default is only a handler for posts.
     241     */
     242    $search_handlers = apply_filters( 'wp_rest_search_handlers', array( new WP_REST_Post_Search_Handler() ) );
     243
     244    $controller = new WP_REST_Search_Controller( $search_handlers );
    231245    $controller->register_routes();
    232246
Note: See TracChangeset for help on using the changeset viewer.