jetpack
/
jetpack_vendor
/
automattic
/
jetpack-premium-analytics
/
src
/
class-dashboard-support-routes.php
REST
3 weeks ago
Reports
3 weeks ago
Sync
3 weeks ago
class-analytics.php
3 weeks ago
class-capabilities.php
3 weeks ago
class-connection-configuration.php
3 weeks ago
class-dashboard-section-registry.php
3 weeks ago
class-dashboard-section.php
3 weeks ago
class-dashboard-support-routes.php
3 weeks ago
class-jetpack-stats-tracker.php
3 weeks ago
class-notices.php
3 weeks ago
class-widget-type-registry.php
3 weeks ago
class-widget-type.php
3 weeks ago
class-woocommerce-analytics-tracker.php
3 weeks ago
csv-exports.php
3 weeks ago
dashboard-grammar.php
3 weeks ago
dashboard-layout.php
3 weeks ago
dashboard-sections.php
3 weeks ago
rest-namespace.php
3 weeks ago
widget-availability.php
3 weeks ago
widget-i18n.json
3 weeks ago
widget-modules.php
3 weeks ago
widget-type-support.php
3 weeks ago
widget-types.php
3 weeks ago
class-dashboard-support-routes.php
71 lines
| 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, default |
| 13 | * layout, sections) 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. dashboard-sections.php hydrates |
| 41 | * its own section registry at file scope, which should not run before |
| 42 | * WordPress has decided this request is actually dispatching a REST route. |
| 43 | * widget-modules.php hydrates the widget type registry itself, lazily, |
| 44 | * only when its REST callback or the boot-deps filter actually runs. |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public static function boot_routes() { |
| 49 | // Guarded on a symbol from each file: two copies of this package can be loaded |
| 50 | // in one request, and these file-scope functions are outside the autoloader's |
| 51 | // dedupe. See Analytics::load_dashboard_components() for the full rationale. |
| 52 | if ( ! function_exists( __NAMESPACE__ . '\\register_widget_modules_rest_route' ) ) { |
| 53 | require_once __DIR__ . '/widget-modules.php'; |
| 54 | } |
| 55 | if ( ! function_exists( __NAMESPACE__ . '\\register_dashboard_default_layout_route' ) ) { |
| 56 | require_once __DIR__ . '/dashboard-layout.php'; |
| 57 | } |
| 58 | if ( ! function_exists( __NAMESPACE__ . '\\register_dashboard_section' ) ) { |
| 59 | require_once __DIR__ . '/dashboard-sections.php'; |
| 60 | } |
| 61 | |
| 62 | // These routes are gated on the dashboard capability, and WPCOM Simple boots |
| 63 | // this class standalone, without going through Analytics::init(). |
| 64 | Capabilities::register(); |
| 65 | |
| 66 | register_widget_modules_rest_route(); |
| 67 | register_dashboard_default_layout_route(); |
| 68 | register_dashboard_sections_rest_routes(); |
| 69 | } |
| 70 | } |
| 71 |