← All changes
|
_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-search.php
+12
-3
13.1.5
→
16.3-a.7
View file →
| @@ -6,8 +6,12 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | use Automattic\Jetpack\Search\REST_Controller; |
| 9 | 9 | |
| 10 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + exit( 0 ); | |
| 12 | +} | |
| 13 | + | |
| 10 | 14 | /** |
| 11 | 15 | * Jetpack Search: Makes authenticated requests to the site search API using blog tokens. |
| 12 | 16 | * This endpoint will only be used when trying to search private Jetpack and WordPress.com sites. |
| 13 | 17 | * |
| @@ -24,11 +28,10 @@ | ||
| 24 | 28 | /** |
| 25 | 29 | * Constructor. |
| 26 | 30 | */ |
| 27 | 31 | public function __construct() { |
| 28 | - $this->namespace = 'wpcom/v2'; | |
| 29 | - $this->rest_base = 'search'; | |
| 30 | - $this->controller = new REST_Controller( defined( 'IS_WPCOM' ) && IS_WPCOM ); | |
| 32 | + $this->namespace = 'wpcom/v2'; | |
| 33 | + $this->rest_base = 'search'; | |
| 31 | 34 | |
| 32 | 35 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 33 | 36 | } |
| 34 | 37 | |
| @@ -33,10 +36,16 @@ | ||
| 33 | 36 | } |
| 34 | 37 | |
| 35 | 38 | /** |
| 36 | 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. | |
| 37 | 44 | */ |
| 38 | 45 | public function register_routes() { |
| 46 | + $this->controller = new REST_Controller( defined( 'IS_WPCOM' ) && IS_WPCOM ); | |
| 47 | + | |
| 39 | 48 | register_rest_route( |
| 40 | 49 | $this->namespace, |
| 41 | 50 | $this->rest_base, |
| 42 | 51 | array( |