Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
69.40% covered (warning)
69.40%
93 / 134
52.38% covered (warning)
52.38%
11 / 21
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Activity_Log
69.70% covered (warning)
69.70%
92 / 132
52.38% covered (warning)
52.38%
11 / 21
135.14
0.00% covered (danger)
0.00%
0 / 1
 initialize
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
5
 is_module_active
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 register_module
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 add_standalone_module
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 activate_standalone_default
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
4.07
 add_wp_admin_submenu
89.29% covered (warning)
89.29%
25 / 28
0.00% covered (danger)
0.00%
0 / 1
6.04
 add_admin_shell_member
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
 load_as_admin_shell_guest
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 is_available
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
4.37
 admin_init
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
 load_wp_build
23.08% covered (danger)
23.08%
3 / 13
0.00% covered (danger)
0.00%
0 / 1
7.10
 load_wp_build_with_screen_alias
75.00% covered (warning)
75.00%
9 / 12
0.00% covered (danger)
0.00%
0 / 1
2.06
 alias_screen_id_for_wp_build
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 restore_screen_id_after_wp_build
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 opt_out_of_jitms
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 hide_jitms_on_wp_build_dashboard
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 enqueue_initial_state
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 is_wpcom_simple
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 render_fallback
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_activity_log_admin_request
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 register_rest_routes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Primary class for the Jetpack Activity Log package.
4 *
5 * @package automattic/jetpack-activity-log
6 */
7
8namespace Automattic\Jetpack\Activity_Log;
9
10if ( ! defined( 'ABSPATH' ) ) {
11    exit( 0 );
12}
13
14use Automattic\Jetpack\Activity_Log\Initial_State as Activity_Log_Initial_State;
15use Automattic\Jetpack\Admin_UI\Admin_Menu;
16use Automattic\Jetpack\Admin_UI\Admin_Shell;
17use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
18use Automattic\Jetpack\Connection\Manager as Connection_Manager;
19use Automattic\Jetpack\Modules;
20use Automattic\Jetpack\Status\Host;
21use Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Polyfills;
22use Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Screen_Id;
23use Jetpack_Options;
24use function add_action;
25use function add_filter;
26use function add_submenu_page;
27use function class_exists;
28use function current_user_can;
29use function did_action;
30use function do_action;
31use function get_current_screen;
32use function is_admin;
33use function is_multisite;
34use function sanitize_text_field;
35use function wp_add_inline_script;
36use function wp_enqueue_script;
37use function wp_register_script;
38use function wp_unslash;
39use function wp_verify_nonce;
40
41/**
42 * Class Jetpack_Activity_Log
43 *
44 * Registers the Activity Log admin page and its REST routes inside the
45 * main Jetpack plugin.
46 */
47class Jetpack_Activity_Log {
48
49    /**
50     * Admin page slug.
51     *
52     * @var string
53     */
54    const PAGE_SLUG = 'jetpack-activity-log';
55
56    /**
57     * Slug of the Jetpack module that turns the Activity Log on and off.
58     *
59     * @var string
60     */
61    const MODULE_SLUG = 'activity-log';
62
63    /**
64     * Jetpack_Options key recording that the module was switched on for a site
65     * with no Jetpack plugin. See `activate_standalone_default()`.
66     *
67     * @var string
68     */
69    const DEFAULT_ACTIVATED_OPTION = 'activity_log_default_activated';
70
71    /**
72     * Page slug for the wp-build dashboard. Distinct from the wp-admin menu
73     * slug (`PAGE_SLUG`) so the user-facing URL stays `admin.php?page=jetpack-activity-log`;
74     * we alias the current screen id to this value so wp-build's
75     * screen-match enqueue callback fires. Must match the `page` in
76     * `routes/dashboard/package.json` and the `wpPlugin.pages` entry.
77     *
78     * @var string
79     */
80    const WP_BUILD_PAGE_SLUG = 'jetpack-activity-log-dashboard';
81
82    /**
83     * Handle for the classic script that carries the React initial state.
84     * The dashboard is a wp-build script module, so there is no classic
85     * bundle handle to attach inline data to — this empty handle exists
86     * purely to print `JPACTIVITYLOG_INITIAL_STATE` and the Connection
87     * initial state before boot runs.
88     *
89     * @var string
90     */
91    const DATA_SCRIPT_HANDLE = 'jetpack-activity-log-data';
92
93    /**
94     * Nonce action for refreshing the access flag after a checkout
95     * return. Used by `admin_init()` below and exposed to the client via
96     * Initial_State so the upsell CTA can embed a valid nonce in its
97     * `redirect_to`. Same shape as `Social_Admin_Page::REFRESH_PLAN_NONCE_ACTION`.
98     *
99     * @var string
100     */
101    const REFRESH_ACCESS_NONCE_ACTION = 'jetpack_activity_log_refresh_access';
102
103    /**
104     * The screen ID alias_screen_id_for_wp_build() replaced, until it is restored.
105     *
106     * @var string|null
107     */
108    private static $wp_build_original_screen_id = null;
109
110    /**
111     * The dashboard screen hide_jitms_on_wp_build_dashboard() opts out of JITMs.
112     *
113     * @var string|null
114     */
115    private static $jitm_opt_out_screen_id = null;
116
117    /**
118     * Entry point. Idempotent: safe to call from multiple bootstraps.
119     *
120     * Bootstraps only while the `activity-log` module is on, so the toggle
121     * means the same thing to the Jetpack plugin and to every standalone
122     * plugin that carries this package.
123     */
124    public static function initialize() {
125        // Simple has no module system, and jetpack-mu-wpcom registers the page itself via add_wp_admin_submenu().
126        if ( self::is_wpcom_simple() ) {
127            return;
128        }
129
130        self::register_module();
131
132        if ( did_action( 'jetpack_activity_log_initialized' ) || ! self::is_module_active() ) {
133            return;
134        }
135
136        add_action( 'admin_menu', array( __CLASS__, 'add_wp_admin_submenu' ) );
137        add_action( 'rest_api_init', array( __CLASS__, 'register_rest_routes' ) );
138        add_filter( 'jetpack_package_versions', array( Package_Version::class, 'send_package_version_to_tracker' ) );
139
140        if ( class_exists( Admin_Shell::class ) ) {
141            add_filter( 'jetpack_admin_shell_members', array( __CLASS__, 'add_admin_shell_member' ) );
142        }
143
144        /**
145         * Fires once the Jetpack Activity Log package has wired its hooks.
146         *
147         * @since 0.1.0
148         */
149        do_action( 'jetpack_activity_log_initialized' );
150    }
151
152    /**
153     * Whether the Activity Log module is switched on.
154     *
155     * @return bool
156     */
157    public static function is_module_active() {
158        return ( new Modules() )->is_active( self::MODULE_SLUG );
159    }
160
161    /**
162     * Make the module controllable, and give a site with no Jetpack plugin the
163     * same default-on state the Jetpack plugin gets from `Auto Activate: Yes`.
164     *
165     * @return void
166     */
167    private static function register_module() {
168        add_filter( 'jetpack_get_available_standalone_modules', array( __CLASS__, 'add_standalone_module' ) );
169
170        // `class_exists( 'Jetpack' )` is only reliable once every plugin file has
171        // loaded: `jetpack-backup/` sorts before `jetpack/` in active_plugins, so
172        // Backup reaches initialize() while the Jetpack class is still undefined.
173        if ( did_action( 'plugins_loaded' ) ) {
174            self::activate_standalone_default();
175        } else {
176            add_action( 'plugins_loaded', array( __CLASS__, 'activate_standalone_default' ) );
177        }
178    }
179
180    /**
181     * Make the module available to the module controller when the Jetpack
182     * plugin is not installed, so `jetpack_active_modules` is not inert there.
183     *
184     * @param array $modules Available standalone module slugs.
185     * @return array
186     */
187    public static function add_standalone_module( $modules ) {
188        $modules[] = self::MODULE_SLUG;
189
190        return array_values( array_unique( $modules ) );
191    }
192
193    /**
194     * Switch the module on once on a site with no Jetpack plugin.
195     *
196     * The Jetpack plugin activates the module for you via `Auto Activate: Yes`;
197     * a standalone install has no equivalent, so without this the page would
198     * disappear from every Backup/Boost/Protect/Search/VideoPress site on
199     * upgrade. Recorded in an option rather than repeated, so a later opt-out
200     * is not undone on the next request.
201     *
202     * @return void
203     */
204    public static function activate_standalone_default() {
205        if ( class_exists( 'Jetpack' ) || Jetpack_Options::get_option( self::DEFAULT_ACTIVATED_OPTION ) ) {
206            return;
207        }
208
209        if ( ! ( new Modules() )->activate( self::MODULE_SLUG, false, false ) ) {
210            return;
211        }
212
213        // Record before re-entering initialize(), which calls back into here.
214        Jetpack_Options::update_option( self::DEFAULT_ACTIVATED_OPTION, true );
215
216        // initialize() ran before this and found the module off, so wire up now
217        // rather than leaving the page missing for the rest of the request.
218        self::initialize();
219    }
220
221    /**
222     * Register the Activity Log submenu under Jetpack.
223     *
224     * Mirrors the gating used by the legacy my-jetpack "Activity Log" menu
225     * item (connected user + non-multisite). On WordPress.com Simple sites,
226     * jetpack-mu-wpcom calls this once it has built the Jetpack menu.
227     *
228     * @since 0.6.0 Registers the page on WordPress.com Simple sites.
229     *
230     * @return string|null The resulting page's hook suffix, if registered.
231     */
232    public static function add_wp_admin_submenu() {
233        if ( ! self::is_available() ) {
234            return null;
235        }
236
237        // Load wp-build only on the Activity Log request so its generated
238        // render function exists before the menu callback runs, and its
239        // enqueue pipeline/polyfills stay off every other admin page.
240        if ( self::is_activity_log_admin_request() ) {
241            self::load_wp_build_with_screen_alias();
242        }
243
244        // The menu item must appear on every admin page, but the generated
245        // render function is only loaded on the Activity Log request (above).
246        // The callback is only ever invoked while rendering our page — where
247        // the function is loaded — so the fallback is purely defensive.
248        $render_callback = function_exists( 'jetpack_activity_log_jetpack_activity_log_dashboard_wp_admin_render_page' )
249            ? 'jetpack_activity_log_jetpack_activity_log_dashboard_wp_admin_render_page'
250            : array( __CLASS__, 'render_fallback' );
251
252        if ( self::is_wpcom_simple() ) {
253            // jetpack-mu-wpcom calls this after Admin_Menu has already flushed its queue.
254            $page_suffix = add_submenu_page(
255                'jetpack',
256                /** "Activity Log" is a product name, do not translate. */
257                'Activity Log',
258                'Activity Log',
259                'manage_options',
260                self::PAGE_SLUG,
261                $render_callback
262            );
263        } else {
264            $page_suffix = Admin_Menu::add_menu(
265                /** "Activity Log" is a product name, do not translate. */
266                'Activity Log',
267                'Activity Log',
268                'manage_options',
269                self::PAGE_SLUG,
270                $render_callback
271            );
272        }
273
274        if ( ! $page_suffix ) {
275            return null;
276        }
277
278        add_action( 'load-' . $page_suffix, array( __CLASS__, 'admin_init' ) );
279        self::opt_out_of_jitms( $page_suffix );
280
281        return $page_suffix;
282    }
283
284    /**
285     * Register the Activity Log with the admin shell, which switches between Jetpack dashboards without a page load.
286     *
287     * @since $$next-version$$
288     *
289     * @param array $members Shell members keyed by admin page slug.
290     * @return array
291     */
292    public static function add_admin_shell_member( $members ) {
293        if ( ! self::is_available() || ! file_exists( dirname( __DIR__ ) . '/build/build.php' ) ) {
294            return $members;
295        }
296
297        $members[ self::PAGE_SLUG ] = array(
298            'build_prefix' => 'jetpack_activity_log',
299            'build_page'   => self::WP_BUILD_PAGE_SLUG,
300            'init_modules' => array( '@jetpack-activity-log/init' ),
301            /** "Activity Log" is a product name, do not translate. */
302            'title'        => 'Activity Log',
303            'capability'   => 'manage_options',
304            'handles'      => array( self::DATA_SCRIPT_HANDLE, 'jetpack-script-data', 'jp-tracks', 'wp-jp-i18n-loader' ),
305            'load'         => array( __CLASS__, 'load_as_admin_shell_guest' ),
306        );
307        return $members;
308    }
309
310    /**
311     * Ready the Activity Log routes and page data while another dashboard's page is open, without the screen ID alias.
312     *
313     * @since $$next-version$$
314     *
315     * @return void
316     */
317    public static function load_as_admin_shell_guest() {
318        self::load_wp_build();
319        add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_initial_state' ) );
320    }
321
322    /**
323     * Whether the Activity Log page should be shown to the current user.
324     *
325     * @return bool
326     */
327    public static function is_available() {
328        if ( ! current_user_can( 'manage_options' ) ) {
329            return false;
330        }
331
332        // Simple sites need no Jetpack connection: their users are WordPress.com users.
333        if ( self::is_wpcom_simple() ) {
334            return true;
335        }
336
337        if ( is_multisite() ) {
338            return false;
339        }
340
341        return ( new Connection_Manager() )->is_user_connected();
342    }
343
344    /**
345     * Fires when the admin page is loaded.
346     *
347     * When the user is returning from a successful checkout, the upsell
348     * CTA appends `?refresh_access=1&_wpnonce=…` to the `redirect_to`
349     * value it hands off to WordPress.com. Detect that here, verify the
350     * nonce, and drop the cached paid-plan signal so
351     * `Initial_State::get_data()` (which runs later in the same request,
352     * when the bundle is enqueued) rehydrates from WPCOM instead of
353     * re-serving the pre-checkout value. Mirrors the pattern in
354     * `Automattic\Jetpack\Publicize\Social_Admin_Page::admin_init()`.
355     */
356    public static function admin_init() {
357        if ( isset( $_GET['refresh_access'] ) && isset( $_GET['_wpnonce'] ) ) {
358            $nonce = sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) );
359            if ( wp_verify_nonce( $nonce, self::REFRESH_ACCESS_NONCE_ACTION ) ) {
360                REST_Controller::clear_access_cache();
361            }
362        }
363
364        add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_initial_state' ) );
365    }
366
367    /**
368     * Require the generated wp-build entry and register the script/module
369     * polyfills the boot bundle depends on.
370     *
371     * The boot bundle depends on `@wordpress/*` handles (e.g. `wp-theme`,
372     * pulled in via `@wordpress/ui`) that Core does not register on older
373     * WordPress versions. Without them WP_Scripts silently drops the bundle
374     * and the page renders blank, so register the polyfills here. Scoped to
375     * the Activity Log request by the sole caller, since the register() call
376     * can force-replace Core handles and must not fire on every admin page.
377     *
378     * @return void
379     */
380    private static function load_wp_build() {
381        $build_index = dirname( __DIR__ ) . '/build/build.php';
382
383        if ( ! file_exists( $build_index ) ) {
384            return;
385        }
386
387        require_once $build_index;
388
389        // The generated `modules.php` registers standalone script modules (the
390        // `@jetpack-activity-log/init` i18n bootstrap) on `wp_default_scripts`.
391        // We load wp-build lazily on `admin_menu`, which can run after that
392        // action has already fired — so the hook may be added too late and the
393        // init module never registers, leaving it out of the import map and
394        // breaking boot. Register directly here (mirroring the polyfills call
395        // below); the generated function guards against double-registration.
396        if ( function_exists( 'jetpack_activity_log_register_script_modules' ) ) {
397            jetpack_activity_log_register_script_modules(); // @phan-suppress-current-line PhanUndeclaredFunction -- Checked with function_exists(); defined in the generated build/modules.php, which Phan excludes.
398        }
399
400        WP_Build_Polyfills::register(
401            'jetpack-activity-log',
402            array_merge(
403                WP_Build_Polyfills::SCRIPT_HANDLES,
404                WP_Build_Polyfills::MODULE_IDS
405            )
406        );
407    }
408
409    /**
410     * Load wp-build with the screen ID aliased across its generated enqueue check.
411     *
412     * @see WP_Build_Screen_Id::load_with_alias()
413     * @return void
414     */
415    private static function load_wp_build_with_screen_alias() {
416        // Fallback: an older wp-build-polyfills under the jetpack-autoloader may predate load_with_alias().
417        if ( method_exists( WP_Build_Screen_Id::class, 'load_with_alias' ) ) {
418            WP_Build_Screen_Id::load_with_alias(
419                array( __CLASS__, 'alias_screen_id_for_wp_build' ),
420                array( __CLASS__, 'restore_screen_id_after_wp_build' ),
421                function () {
422                    self::load_wp_build();
423                }
424            );
425            return;
426        }
427
428        add_action( 'admin_enqueue_scripts', array( __CLASS__, 'alias_screen_id_for_wp_build' ) );
429        self::load_wp_build();
430        add_action( 'admin_enqueue_scripts', array( __CLASS__, 'restore_screen_id_after_wp_build' ) );
431    }
432
433    /**
434     * Alias the current screen id to the wp-build page slug.
435     *
436     * The wp-build-generated enqueue callback only fires when the screen id
437     * equals the wp-build page slug. Our menu slug stays `jetpack-activity-log`,
438     * so alias the screen id in place to make the check pass without changing
439     * the user-facing URL. Hooked only for the Activity Log request, so this
440     * never affects any other screen.
441     *
442     * @since 0.4.1 Takes no argument; hooked on `admin_enqueue_scripts`.
443     *
444     * @return void
445     */
446    public static function alias_screen_id_for_wp_build() {
447        $screen = get_current_screen();
448        if ( ! $screen ) {
449            return;
450        }
451
452        self::$wp_build_original_screen_id = $screen->id;
453        $screen->id                        = self::WP_BUILD_PAGE_SLUG;
454    }
455
456    /**
457     * Undo alias_screen_id_for_wp_build(), so code after the generated check sees the real screen ID.
458     *
459     * @since 0.4.1
460     *
461     * @return void
462     */
463    public static function restore_screen_id_after_wp_build() {
464        $screen = get_current_screen();
465        if ( ! $screen || null === self::$wp_build_original_screen_id ) {
466            return;
467        }
468
469        $screen->id                        = self::$wp_build_original_screen_id;
470        self::$wp_build_original_screen_id = null;
471    }
472
473    /**
474     * Opt the dashboard's screen out of JITMs.
475     *
476     * @param string $screen_id The hook suffix the page was registered under, which is its screen ID.
477     * @return void
478     */
479    private static function opt_out_of_jitms( $screen_id ) {
480        self::$jitm_opt_out_screen_id = $screen_id;
481        add_filter( 'jetpack_display_jitms_on_screen', array( __CLASS__, 'hide_jitms_on_wp_build_dashboard' ), 10, 2 );
482    }
483
484    /**
485     * Keep JITMs off the wp-build dashboard, which has no `#jp-admin-notices` to show them in.
486     *
487     * Fetching a JITM records a view, so one the page hides would still be counted.
488     *
489     * @since 0.4.1
490     *
491     * @param bool   $show      Whether to show JITMs on the screen.
492     * @param string $screen_id The screen ID.
493     * @return bool
494     */
495    public static function hide_jitms_on_wp_build_dashboard( $show, $screen_id ) {
496        if ( null !== self::$jitm_opt_out_screen_id && self::$jitm_opt_out_screen_id === $screen_id ) {
497            return false;
498        }
499
500        return $show;
501    }
502
503    /**
504     * Print the React initial state and the Connection initial state, and load
505     * the Tracks transport.
506     *
507     * The initial state is attached to a dedicated empty classic handle because
508     * the dashboard is a wp-build script module — there is no classic bundle
509     * handle to hang the inline data on. Boot defers its own execution to
510     * `DOMContentLoaded`, so this inline data is always set on `window` first.
511     *
512     * `jp-tracks` (stats.wp.com/w.js) is required for analytics: the dashboard's
513     * `@automattic/jetpack-analytics` events only queue into `window._tkq`
514     * (the package's own w.js loader is disabled), so without this handle no
515     * `jetpack_activity_log_*` event ever flushes. Mirrors Newsletter's
516     * `Settings::load_admin_scripts()`.
517     *
518     * @return void
519     */
520    public static function enqueue_initial_state() {
521        wp_register_script( self::DATA_SCRIPT_HANDLE, false, array(), Package_Version::PACKAGE_VERSION, true );
522        wp_enqueue_script( self::DATA_SCRIPT_HANDLE );
523
524        wp_add_inline_script( self::DATA_SCRIPT_HANDLE, ( new Activity_Log_Initial_State() )->render(), 'before' );
525
526        // Simple has no Jetpack connection to describe; the app treats a missing state as no connection errors.
527        if ( ! self::is_wpcom_simple() ) {
528            Connection_Initial_State::render_script( self::DATA_SCRIPT_HANDLE );
529        }
530
531        wp_enqueue_script( 'jp-tracks', '//stats.wp.com/w.js', array(), gmdate( 'YW' ), true );
532
533        // The dashboard is a wp-build script module: it externalizes
534        // `@wordpress/i18n` to the shared `wp.i18n` global but has no
535        // `wp_set_script_translations()` equivalent to load its JS catalog.
536        // Enqueue Jetpack's i18n loader (`wp.jpI18nLoader`, from jetpack-assets,
537        // registered on `wp_default_scripts`) so the `@jetpack-activity-log/init`
538        // boot module can fetch and install the translation catalog before the
539        // app renders. Without this the UI ships in English on non-English sites.
540        if ( wp_script_is( 'wp-jp-i18n-loader', 'registered' ) ) {
541            wp_enqueue_script( 'wp-jp-i18n-loader' );
542        }
543    }
544
545    /**
546     * Whether this is a WordPress.com Simple site.
547     *
548     * @since 0.6.0
549     *
550     * @return bool
551     */
552    public static function is_wpcom_simple() {
553        return ( new Host() )->is_wpcom_simple();
554    }
555
556    /**
557     * Fallback page body if the generated wp-build render function is
558     * unavailable (e.g. assets not built). Keeps the menu from fataling and
559     * still gives boot its mount container.
560     *
561     * @return void
562     */
563    public static function render_fallback() {
564        echo '<div class="wrap"><div id="jetpack-activity-log-dashboard-wp-admin-app"></div></div>';
565    }
566
567    /**
568     * Whether the current request targets the Activity Log admin page.
569     *
570     * The `$_GET['page']` value is populated by wp-admin/admin.php before any
571     * of our hooks fire, so this check is reliable from `admin_menu` onwards.
572     *
573     * @return bool
574     */
575    private static function is_activity_log_admin_request() {
576        if ( ! is_admin() || ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
577            return false;
578        }
579
580        return sanitize_text_field( wp_unslash( $_GET['page'] ) ) === self::PAGE_SLUG; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
581    }
582
583    /**
584     * Register the REST routes backing the Activity Log UI.
585     *
586     * Routes are added in Phase 2. This method exists now so that the
587     * `jetpack/v4/activity-log` namespace is reserved and the hook is wired.
588     */
589    public static function register_rest_routes() {
590        REST_Controller::register_rest_routes();
591    }
592}