PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 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 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-premium-analytics / src / class-dashboard-support-routes.php

class-dashboard-support-routes.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3, at jetpack_vendor/automattic/jetpack-premium-analytics/src/class-dashboard-support-routes.php

80 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Public entry point for hosts that serve the dashboard support routes
4 * without booting the rest of the package.
5 *
6 * @package automattic/jetpack-premium-analytics
7 */
8
9 namespace Automattic\Jetpack\PremiumAnalytics;
10
11 /**
12 * Registers the dashboard's REST support routes (widget modules, sections)
13 * for a host that never calls Analytics::init().
14 *
15 * WordPress.com Simple serves the dashboard from WPCOM, not the site (see
16 * Analytics::init_wpcom_simple()), so WPCOM's public-api process calls this
17 * directly — see AGENTS.md for the call site and what to update on the WPCOM
18 * side if this changes. Analytics::init() calls the same method for
19 * connected sites, so there's one implementation, not two.
20 */
21 class Dashboard_Support_Routes {
22
23 /**
24 * Register the dashboard support routes.
25 *
26 * Idempotent: safe to call standalone, and safe to call more than once.
27 *
28 * @return void
29 */
30 public static function register() {
31 add_action( 'rest_api_init', array( __CLASS__, 'boot_routes' ) );
32 }
33
34 /**
35 * Load the route files and register their REST routes.
36 *
37 * Deferred here (rest_api_init), not run from register() itself: register()
38 * runs on every request that boots this package, and on WPCOM Simple that's
39 * every request across all of WPCOM's public-api process, most of which
40 * never dispatch a Premium Analytics route. Both registries hydrate lazily,
41 * on their first read: the section registry fires its registration action
42 * then, and widget-modules.php hydrates the widget type registry only when
43 * its REST callback or the boot-deps filter actually runs.
44 *
45 * @return void
46 */
47 public static function boot_routes() {
48 // Load-bearing, not defensive duplication: since WOOA7S-1804 these files load
49 // only in wp-admin, so on REST this method is their only loader.
50 //
51 // Guarded on a symbol from each file: two copies of this package can be loaded
52 // in one request, and these file-scope functions are outside the autoloader's
53 // dedupe. See Analytics::load_dashboard_components() for the full rationale.
54 if ( ! function_exists( __NAMESPACE__ . '\\register_widget_modules_rest_route' ) ) {
55 require_once __DIR__ . '/widget-modules.php';
56 }
57 if ( ! function_exists( __NAMESPACE__ . '\\get_dashboard_default_widget_instance' ) ) {
58 require_once __DIR__ . '/dashboard-layout.php';
59 }
60 if ( ! function_exists( __NAMESPACE__ . '\\register_dashboard_section' ) ) {
61 require_once __DIR__ . '/dashboard-sections.php';
62 }
63 if ( ! function_exists( __NAMESPACE__ . '\\register_default_dashboard_sections' ) ) {
64 require_once __DIR__ . '/default-dashboard-sections.php';
65 }
66 // Copies from before dashboard-sections.php loaded the policy file leave it unloaded.
67 if ( ! function_exists( __NAMESPACE__ . '\\register_dashboard_feature_flags' ) ) {
68 require_once __DIR__ . '/dashboard-policy.php';
69 }
70
71 // These routes are gated on the dashboard capability and read the dashboard flags, and
72 // WPCOM Simple boots this class standalone, without going through Analytics::init().
73 register_dashboard_feature_flags();
74 Capabilities::register();
75
76 register_widget_modules_rest_route();
77 register_dashboard_sections_rest_routes();
78 }
79 }
80