wppaste
WordPress

WP_REST_Search_Controller

Since
5.0.0
Source
wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php:17
Core class to search through all WordPress content via the REST API.

Compatibility

WordPress
since 5.0.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 1

$search_handlersWP_REST_Search_Handler[]protected
Search handlers used by the controller.

Methods · 9

Source code

class WP_REST_Search_Controller extends WP_REST_Controller { 	/**	 * ID property name.	 */	const PROP_ID = 'id'; 	/**	 * Title property name.	 */	const PROP_TITLE = 'title'; 	/**	 * URL property name.	 */	const PROP_URL = 'url'; 	/**	 * Type property name.	 */	const PROP_TYPE = 'type'; 	/**	 * Subtype property name.	 */	const PROP_SUBTYPE = 'subtype'; 	/**	 * Identifier for the 'any' type.	 */	const TYPE_ANY = 'any'; 	/**	 * Search handlers used by the controller.	 *	 * @since 5.0.0	 * @var WP_REST_Search_Handler[]	 */	protected $search_handlers = array(); 	/**	 * Constructor.	 *	 * @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.	 */	public function __construct( array $search_handlers ) {		$this->namespace = 'wp/v2';		$this->rest_base = 'search'; 		foreach ( $search_handlers as $search_handler ) {			if ( ! $search_handler instanceof WP_REST_Search_Handler ) {				_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;			} 			$this->search_handlers[ $search_handler->get_type() ] = $search_handler;		}	} 	/**	 * Registers the routes for the search controller.	 *	 * @since 5.0.0	 *	 * @see register_rest_route()	 */	public function register_routes() {		register_rest_route(			$this->namespace,			'/' . $this->rest_base,			array(				array(

Changelog

Introduced in 5.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.