PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / _inc / lib / core-api / wpcom-endpoints / class-wpcom-rest-api-v2-endpoint-search.php

class-wpcom-rest-api-v2-endpoint-search.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at _inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-search.php

61 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Proxy endpoint for Jetpack Search
4 *
5 * @package automattic/jetpack
6 */
7
8 use Automattic\Jetpack\Search\REST_Controller;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit( 0 );
12 }
13
14 /**
15 * Jetpack Search: Makes authenticated requests to the site search API using blog tokens.
16 * This endpoint will only be used when trying to search private Jetpack and WordPress.com sites.
17 *
18 * @since 9.0.0
19 */
20 class WPCOM_REST_API_V2_Endpoint_Search extends WP_REST_Controller {
21 /**
22 * Forward request to controller in Search package.
23 *
24 * @var REST_Controller
25 */
26 protected $controller;
27
28 /**
29 * Constructor.
30 */
31 public function __construct() {
32 $this->namespace = 'wpcom/v2';
33 $this->rest_base = 'search';
34
35 add_action( 'rest_api_init', array( $this, 'register_routes' ) );
36 }
37
38 /**
39 * Called automatically on `rest_api_init()`.
40 *
41 * The Search package controller is instantiated here rather than in the
42 * constructor so that the package class is only loaded when the REST API is
43 * actually in use, not on every front-end, cron, or login request.
44 */
45 public function register_routes() {
46 $this->controller = new REST_Controller( defined( 'IS_WPCOM' ) && IS_WPCOM );
47
48 register_rest_route(
49 $this->namespace,
50 $this->rest_base,
51 array(
52 'methods' => WP_REST_Server::READABLE,
53 'callback' => array( $this->controller, 'get_search_results' ),
54 'permission_callback' => 'is_user_logged_in',
55 )
56 );
57 }
58 }
59
60 wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Search' );
61