PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 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 All 504 releases
← All changes | _inc/lib/core-api/load-wpcom-endpoints.php +16 -3 13.7.216.3-a.1 View file →
@@ -12,9 +12,9 @@
12 12 /**
13 13 * Disable direct access.
14 14 */
15 15 if ( ! defined( 'ABSPATH' ) ) {
16 - exit;
16 + exit( 0 );
17 17 }
18 18
19 19 /**
20 20 * Loop through endpoint files and load them.
@@ -52,11 +52,24 @@
52 52
53 53 require __DIR__ . '/class-wpcom-rest-field-controller.php';
54 54
55 55 /**
56 - * Load the REST API v2 plugin files during the plugins_loaded action.
56 + * Load the REST API v2 plugin files.
57 + *
58 + * Hooked to `rest_api_init` (priority 5) so the ~37 endpoint class files only
59 + * load on REST requests, not on every front-end page. Priority 5 ensures the
60 + * loader runs before constructors register their own `register_routes` callbacks
61 + * at the default priority 10 within the same `rest_api_init` action.
57 62 */
58 63 function load_wpcom_rest_api_v2_plugin_files() {
59 64 wpcom_rest_api_v2_load_plugin_files( 'wpcom-endpoints/*.php' );
60 65 wpcom_rest_api_v2_load_plugin_files( 'wpcom-fields/*.php' );
61 66 }
62 -add_action( 'plugins_loaded', 'load_wpcom_rest_api_v2_plugin_files' );
67 +add_action( 'rest_api_init', 'load_wpcom_rest_api_v2_plugin_files', 5 );
68 +
69 +// In the PHPUnit test suite, fire the loader during `plugins_loaded` so all 37 endpoint
70 +// classes are defined before PHPUnit performs test discovery. Test files use
71 +// `#[CoversClass( WPCOM_REST_API_V2_Endpoint_*::class )]` attributes that PHPUnit eagerly
72 +// reflects, requiring the classes to be loadable at that moment.
73 +if ( defined( 'PHPUNIT_JETPACK_TESTSUITE' ) && PHPUNIT_JETPACK_TESTSUITE ) {
74 + add_action( 'plugins_loaded', 'load_wpcom_rest_api_v2_plugin_files' );
75 +}