Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.68% covered (warning)
76.68%
148 / 193
50.00% covered (danger)
50.00%
11 / 22
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Boost
76.68% covered (warning)
76.68%
148 / 193
50.00% covered (danger)
50.00%
11 / 22
77.20
0.00% covered (danger)
0.00%
0 / 1
 __construct
93.55% covered (success)
93.55%
29 / 31
0.00% covered (danger)
0.00%
0 / 1
3.00
 register_deactivation_hook
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 schedule_version_change
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
4.12
 handle_version_change
85.71% covered (warning)
85.71%
24 / 28
0.00% covered (danger)
0.00%
0 / 1
9.24
 setup_cron_schedules
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 custom_cron_intervals
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 whitelist_query_args
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 register_feature_flags
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 is_ask_agent_enabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 add_feature_flags_constant
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 activate
94.74% covered (success)
94.74%
18 / 19
0.00% covered (danger)
0.00%
0 / 1
10.01
 deactivate
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 cleanup_image_size_analysis_data
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 init_admin
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 init_jetpack_config
100.00% covered (success)
100.00%
36 / 36
100.00% covered (success)
100.00%
1 / 1
2
 maybe_sync_module_status
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 sync_module_status
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 init_textdomain
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 get_plugin_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_version
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 handle_environment_change
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 uninstall
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @link       https://automattic.com
9 * @since      1.0.0
10 * @package    automattic/jetpack-boost
11 */
12
13namespace Automattic\Jetpack_Boost;
14
15use Automattic\Jetpack\Activity_Log\Jetpack_Activity_Log;
16use Automattic\Jetpack\Boost_Core\Lib\Transient;
17use Automattic\Jetpack\Boost_Speed_Score\Speed_Score_History;
18use Automattic\Jetpack\Config as Jetpack_Config;
19use Automattic\Jetpack\Feature_Flags\Feature_Flags;
20use Automattic\Jetpack\Image_CDN\Image_CDN_Core;
21use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
22use Automattic\Jetpack\Plugin_Deactivation\Deactivation_Handler;
23use Automattic\Jetpack_Boost\Admin\Admin;
24use Automattic\Jetpack_Boost\Admin\Regenerate_Admin_Notice;
25use Automattic\Jetpack_Boost\Contracts\Sub_Feature;
26use Automattic\Jetpack_Boost\Data_Sync\Getting_Started_Entry;
27use Automattic\Jetpack_Boost\Lib\Analytics;
28use Automattic\Jetpack_Boost\Lib\Cleanup_Transients;
29use Automattic\Jetpack_Boost\Lib\CLI;
30use Automattic\Jetpack_Boost\Lib\Connection;
31use Automattic\Jetpack_Boost\Lib\Cornerstone\Cornerstone_Pages;
32use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_State;
33use Automattic\Jetpack_Boost\Lib\Critical_CSS\Critical_CSS_Storage;
34use Automattic\Jetpack_Boost\Lib\Critical_CSS\Generator;
35use Automattic\Jetpack_Boost\Lib\Setup;
36use Automattic\Jetpack_Boost\Lib\Site_Health;
37use Automattic\Jetpack_Boost\Lib\Status;
38use Automattic\Jetpack_Boost\Lib\Super_Cache_Tracking;
39use Automattic\Jetpack_Boost\Modules\Module;
40use Automattic\Jetpack_Boost\Modules\Modules_Setup;
41use Automattic\Jetpack_Boost\Modules\Optimizations\Lcp\LCP_State;
42use Automattic\Jetpack_Boost\Modules\Optimizations\Lcp\LCP_Storage;
43use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Cache_Preload;
44use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Page_Cache;
45use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Page_Cache_Setup;
46use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Boost_Cache;
47use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Boost_Cache_Settings;
48use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Storage\File_Storage;
49use Automattic\Jetpack_Boost\REST_API\Endpoints\List_Cornerstone_Pages;
50use Automattic\Jetpack_Boost\REST_API\Endpoints\List_LCP_Analysis;
51use Automattic\Jetpack_Boost\REST_API\Endpoints\List_Site_Urls;
52use Automattic\Jetpack_Boost\REST_API\Endpoints\List_Source_Providers;
53use Automattic\Jetpack_Boost\REST_API\REST_API;
54
55/**
56 * The core plugin class.
57 *
58 * This is used to define internationalization, admin-specific hooks, and
59 * public-facing site hooks.
60 *
61 * Also maintains the unique identifier of this plugin as well as the current
62 * version of the plugin.
63 *
64 * @since      1.0.0
65 * @author     Automattic <support@jetpack.com>
66 *
67 * @phan-constructor-used-for-side-effects
68 */
69class Jetpack_Boost {
70
71    /**
72     * Feature flag for the "Ask your agent" button on the speed score card.
73     */
74    const ASK_AGENT_FLAG = 'boost-ask-your-agent';
75
76    /**
77     * The unique identifier of this plugin.
78     *
79     * @since    1.0.0
80     * @var string The string used to uniquely identify this plugin.
81     */
82    private $plugin_name;
83
84    /**
85     * The current version of the plugin.
86     *
87     * @since    1.0.0
88     * @var string The current version of the plugin.
89     */
90    private $version;
91
92    /**
93     * The Jetpack Boost Connection manager instance.
94     *
95     * @since    1.0.0
96     * @access   public
97     * @var Connection The Jetpack Boost Connection manager instance.
98     */
99    public $connection;
100
101    /**
102     * Define the core functionality of the plugin.
103     *
104     * Set the plugin name and the plugin version that can be used throughout the plugin.
105     * Load the dependencies, define the locale, and set the hooks for the admin area and
106     * the public-facing side of the site.
107     *
108     * @since    1.0.0
109     */
110    public function __construct() {
111        $this->version     = JETPACK_BOOST_VERSION;
112        $this->plugin_name = 'jetpack-boost';
113
114        self::register_feature_flags();
115        add_filter( 'jetpack_boost_js_constants', array( self::class, 'add_feature_flags_constant' ) );
116
117        $this->connection = new Connection();
118        $this->connection->init();
119
120        $this->register_deactivation_hook();
121
122        if ( defined( 'WP_CLI' ) && WP_CLI ) {
123            $cli_instance = new CLI( $this );
124            \WP_CLI::add_command( 'jetpack-boost', $cli_instance );
125        }
126
127        $modules_setup = new Modules_Setup();
128        Setup::add( $modules_setup );
129
130        $cornerstone_pages = new Cornerstone_Pages();
131        Setup::add( $cornerstone_pages );
132
133        // Initialize Jetpack packages (connection, sync, identity crisis).
134        $this->init_jetpack_config();
135
136        // Initialize the Admin experience.
137        $this->init_admin( $modules_setup );
138
139        add_action( 'admin_init', array( $this, 'schedule_version_change' ) );
140
141        add_action( 'init', array( $this, 'init_textdomain' ) );
142        add_action( 'init', array( $this, 'setup_cron_schedules' ) );
143
144        add_action( 'jetpack_boost_environment_changed', array( $this, 'handle_environment_change' ), 10, 2 );
145
146        add_action( 'jetpack_boost_handle_version_change_cron', array( $this, 'handle_version_change' ) );
147
148        add_action( 'jetpack_boost_general_cleanup', array( Cleanup_Transients::class, 'run_cleanup' ) );
149        add_action( Cleanup_Transients::FOLLOWUP_HOOK, array( Cleanup_Transients::class, 'run_cleanup' ) );
150
151        // Fired when plugin ready.
152        do_action( 'jetpack_boost_loaded', $this );
153
154        My_Jetpack_Initializer::init();
155
156        // Activity Log. No-ops while the `activity-log` module is off.
157        Jetpack_Activity_Log::initialize();
158
159        Deactivation_Handler::init( $this->plugin_name, __DIR__ . '/admin/deactivation-dialog.php' );
160
161        // Register the core Image CDN hooks.
162        Image_CDN_Core::setup();
163
164        // Setup Site Health panel functionality.
165        Site_Health::init();
166
167        Super_Cache_Tracking::setup();
168
169        // Boost abilities (WP Abilities API). Gated by `jetpack_wp_abilities_enabled`;
170        // priority 20 leaves room for default-priority filter registrations to land first.
171        add_action( 'plugins_loaded', array( '\Automattic\Jetpack_Boost\Abilities\Boost_Abilities', 'init' ), 20 );
172    }
173
174    /**
175     * Register deactivation hook.
176     */
177    private function register_deactivation_hook() {
178        $plugin_file = trailingslashit( dirname( __DIR__ ) ) . 'jetpack-boost.php';
179        register_deactivation_hook( $plugin_file, array( $this, 'deactivate' ) );
180    }
181
182    public function schedule_version_change() {
183        $version = get_option( 'jetpack_boost_version' );
184
185        if ( $version === JETPACK_BOOST_VERSION ) {
186            return;
187        }
188        update_option( 'jetpack_boost_version', JETPACK_BOOST_VERSION );
189
190        // Schedule the cron event to handle the version change. This ensures the previous version's handle is always flushed.
191        if ( ! wp_next_scheduled( 'jetpack_boost_handle_version_change_cron' ) ) {
192            wp_schedule_single_event( time() + 2, 'jetpack_boost_handle_version_change_cron' );
193        }
194    }
195
196    public function handle_version_change() {
197        // Remove this option to prevent the notice from showing up.
198        delete_site_option( 'jetpack_boost_static_minification' );
199
200        jetpack_boost_minify_empty_caches_for_rules();
201
202        // Add upgrade check for Cornerstone Pages.
203        $pages = jetpack_boost_ds_get( 'cornerstone_pages_list' );
204        if ( is_array( $pages ) && in_array( home_url( '' ), $pages, true ) ) {
205            // Remove homepage (empty string) from the cornerstone pages list.
206            $pages = array_filter(
207                $pages,
208                function ( $page ) {
209                    return $page !== home_url( '' );
210                }
211            );
212            jetpack_boost_ds_set( 'cornerstone_pages_list', $pages );
213        }
214
215        if ( jetpack_boost_minify_is_enabled() ) {
216            // We need to clear Minify scheduled events to ensure the latest scheduled jobs are only scheduled irrespective of scheduled arguments.
217            jetpack_boost_minify_clear_scheduled_events();
218            jetpack_boost_minify_activation();
219        }
220
221        if ( ! get_option( 'jetpack_boost_page_cache_uri_keys' ) ) {
222            $home_url  = home_url();
223            $home_host = wp_parse_url( $home_url, PHP_URL_HOST );
224            if ( is_string( $home_host ) ) {
225                $home_port = wp_parse_url( $home_url, PHP_URL_PORT );
226                if ( is_int( $home_port ) ) {
227                    $home_host .= ':' . $home_port;
228                }
229                ( new Boost_Cache( new File_Storage( strtolower( $home_host ) ) ) )->delete_recursive( $home_url );
230            }
231            update_option( 'jetpack_boost_page_cache_uri_keys', 1, false );
232        }
233
234        $page_cache = new Module( new Page_Cache() );
235        if ( $page_cache->is_enabled() ) {
236            // Schedule the cronjob to preload the cache for Cornerstone Pages.
237            ( new Cache_Preload() )->schedule_cornerstone_cronjob();
238        }
239
240        // Setup a cleanup job
241        if ( ! wp_next_scheduled( 'jetpack_boost_general_cleanup' ) ) {
242            wp_schedule_event( time(), 'daily', 'jetpack_boost_general_cleanup' );
243        }
244    }
245
246    /**
247     * Adds the custom cron intervals to the schedules list.
248     */
249    public function setup_cron_schedules() {
250        add_filter( 'cron_schedules', array( $this, 'custom_cron_intervals' ) );
251    }
252
253    /**
254     * Adds custom cron intervals used by Boost.
255     *
256     * @param array $schedules The existing cron schedules.
257     * @return array The modified cron schedules.
258     *
259     * @since 3.12.0
260     */
261    public function custom_cron_intervals( $schedules ) {
262        // The "twicehourly" name maintains the same pattern as the default "twicedaily" name.
263        if ( ! isset( $schedules['twicehourly'] ) ) {
264            $schedules['twicehourly'] = array(
265                'interval' => 30 * MINUTE_IN_SECONDS,
266                'display'  => __( 'Twice Hourly', 'jetpack-boost' ),
267            );
268        }
269        return $schedules;
270    }
271
272    /**
273     * Add query args used by Boost to a list of allowed query args.
274     *
275     * @param array $allowed_query_args The list of allowed query args.
276     *
277     * @return array The modified list of allowed query args.
278     */
279    public static function whitelist_query_args( $allowed_query_args ) {
280        $allowed_query_args[] = Generator::GENERATE_QUERY_ACTION;
281        $allowed_query_args[] = Module::DISABLE_MODULE_QUERY_VAR;
282        return $allowed_query_args;
283    }
284
285    /**
286     * Register Boost's feature flags.
287     *
288     * Runs from the constructor, so WP-CLI, REST and admin requests all see them.
289     */
290    public static function register_feature_flags() {
291        Feature_Flags::register(
292            self::ASK_AGENT_FLAG,
293            array(
294                'default'     => false,
295                'description' => 'Show an "Ask your agent" button on the speed score card that previews and copies a prompt about the scores.',
296                'owner'       => 'jetpack-boost',
297            )
298        );
299    }
300
301    /**
302     * Whether the "Ask your agent" button is enabled on this site.
303     *
304     * @return bool
305     */
306    public static function is_ask_agent_enabled() {
307        return Feature_Flags::is_enabled( self::ASK_AGENT_FLAG );
308    }
309
310    /**
311     * Hand the feature flags to the dashboard script.
312     *
313     * @param array $constants The constants passed to the dashboard script.
314     * @return array
315     */
316    public static function add_feature_flags_constant( $constants ) {
317        $constants['featureFlags'] = array(
318            self::ASK_AGENT_FLAG => self::is_ask_agent_enabled(),
319        );
320        return $constants;
321    }
322
323    /**
324     * Plugin activation handler.
325     */
326    public static function activate() {
327        // Make sure user sees the "Get Started" when first time opening.
328        ( new Getting_Started_Entry() )->set( true );
329        Analytics::record_user_event( 'activate_plugin' );
330
331        $page_cache_status = new Status( Page_Cache::get_slug() );
332        if ( $page_cache_status->get() && Boost_Cache_Settings::get_instance()->get_enabled() ) {
333            Page_Cache_Setup::run_setup();
334        }
335
336        $modules_setup = new Modules_Setup();
337
338        // Setup a cleanup job
339        if ( ! wp_next_scheduled( 'jetpack_boost_general_cleanup' ) ) {
340            wp_schedule_event( time(), 'daily', 'jetpack_boost_general_cleanup' );
341        }
342
343        /*
344         * Check what modules are already active (from a previous activation for example).
345         * If there are active modules, we need to ensure each module-related event is triggered again.
346         */
347        $active_modules = $modules_setup->get_status();
348        if (
349            ! empty( $active_modules )
350            && ( new Connection() )->is_connected()
351        ) {
352            $available_modules = $modules_setup->get_available_modules_and_submodules();
353            foreach ( $active_modules as $module => $status ) {
354                if ( ! $status ) {
355                    continue;
356                }
357
358                $module_instance = $available_modules[ $module ];
359                if ( $module_instance->feature instanceof Sub_Feature && empty( $module_instance->get_active_parent_modules() ) ) {
360                    continue;
361                }
362
363                $modules_setup->on_module_status_update( $module, true );
364            }
365        }
366    }
367
368    /**
369     * Plugin deactivation handler. Clear cache, and reset admin notices.
370     */
371    public function deactivate() {
372        do_action( 'jetpack_boost_deactivate' );
373
374        wp_clear_scheduled_hook( 'jetpack_boost_general_cleanup' );
375        wp_clear_scheduled_hook( Cleanup_Transients::FOLLOWUP_HOOK );
376
377        // Tell Minify JS/CSS to clean up.
378        jetpack_boost_page_optimize_deactivate();
379
380        Regenerate_Admin_Notice::dismiss();
381        Analytics::record_user_event( 'deactivate_plugin' );
382        Page_Cache_Setup::deactivate();
383
384        // Clean up Image Size Analysis data.
385        $this->cleanup_image_size_analysis_data();
386    }
387
388    /**
389     * Clean up Image Size Analysis data from the database.
390     *
391     * @since 4.3.0
392     */
393    private function cleanup_image_size_analysis_data() {
394        global $wpdb;
395
396        // Delete all post meta entries for Image Size Analysis fixes.
397        //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
398        $wpdb->delete(
399            $wpdb->postmeta,
400            array( 'meta_key' => '_jb_image_fixes' ),
401            array( '%s' )
402        );
403    }
404
405    /**
406     * Initialize the admin experience.
407     */
408    public function init_admin( $modules_setup ) {
409        REST_API::register( List_Site_Urls::class );
410        REST_API::register( List_Source_Providers::class );
411        REST_API::register( List_Cornerstone_Pages::class );
412        REST_API::register( List_LCP_Analysis::class );
413
414        ( new Admin() )->init( $modules_setup );
415    }
416
417    /**
418     * Initialize Jetpack packages via the Config class.
419     *
420     * Consolidates connection, sync, and identity crisis initialization
421     * into a single Config instance, matching the pattern used by other
422     * standalone Jetpack plugins (Protect, Social, VideoPress, etc.).
423     */
424    private function init_jetpack_config() {
425        $jetpack_config = new Jetpack_Config();
426
427        /**
428         * Filter that fakes the connection to WordPress.com. Useful for testing.
429         *
430         * @param bool $connection Return true to fake the connection.
431         *
432         * @since 1.0.0
433         */
434        if ( ! apply_filters( 'jetpack_boost_connection_bypass', false ) ) {
435            $jetpack_config->ensure(
436                'connection',
437                array(
438                    'slug'     => JETPACK_BOOST_SLUG,
439                    'name'     => 'Jetpack Boost',
440                    'url_info' => '',
441                )
442            );
443        }
444
445        $jetpack_config->ensure(
446            'sync',
447            array(
448                // Closures defer construction (and option reads) to Sync invocation time.
449                'jetpack_sync_callable_whitelist' => array(
450                    // boost_sub_modules_state was removed: it pointed at a method that never
451                    // existed, so the callable never resolved and Sync never sent it.
452                    'boost_modules'                => static function () {
453                        return ( new Modules_Setup() )->get_status();
454                    },
455                    'boost_latest_scores'          => static function () {
456                        return ( new Speed_Score_History( get_home_url() ) )->latest();
457                    },
458                    'boost_latest_no_boost_scores' => static function () {
459                        return ( new Speed_Score_History( add_query_arg( Module::DISABLE_MODULE_QUERY_VAR, 'all', get_home_url() ) ) )->latest();
460                    },
461                    'critical_css_state'           => static function () {
462                        return ( new Critical_CSS_State() )->get();
463                    },
464                    'lcp_state'                    => static function () {
465                        return ( new LCP_State() )->get();
466                    },
467                ),
468            )
469        );
470
471        add_action( 'added_option', array( $this, 'maybe_sync_module_status' ) );
472        add_action( 'updated_option', array( $this, 'maybe_sync_module_status' ) );
473        add_action( 'deleted_option', array( $this, 'maybe_sync_module_status' ) );
474
475        $jetpack_config->ensure( 'identity_crisis' );
476    }
477
478    /**
479     * Queue a fresh `boost_modules` snapshot when a module status option changes.
480     *
481     * Sync sends callables only when something else triggers a send, so a toggle alone can leave WP.com stale.
482     *
483     * @param string $option Option name.
484     */
485    public function maybe_sync_module_status( $option ) {
486        if ( ! str_starts_with( $option, Status::OPTION_PREFIX ) ) {
487            return;
488        }
489
490        // Deferred: some writes land before Sync's listener loads, and mapped modules change after the toggle.
491        add_action( 'shutdown', array( $this, 'sync_module_status' ) );
492    }
493
494    /**
495     * Send the current module status map to WP.com.
496     *
497     * This skips Sync's callable checksum, so its next routine callables check may send the same map again.
498     */
499    public function sync_module_status() {
500        do_action( 'jetpack_sync_callable', 'boost_modules', ( new Modules_Setup() )->get_status() );
501    }
502
503    /**
504     * Loads the textdomain.
505     */
506    public function init_textdomain() {
507        load_plugin_textdomain(
508            'jetpack-boost',
509            false,
510            JETPACK_BOOST_DIR_PATH . '/languages/'
511        );
512    }
513
514    /**
515     * The name of the plugin used to uniquely identify it within the context of
516     * WordPress and to define internationalization functionality.
517     *
518     * @return string The name of the plugin.
519     * @since     1.0.0
520     */
521    public function get_plugin_name() {
522        return $this->plugin_name;
523    }
524
525    /**
526     * Retrieve the version number of the plugin.
527     *
528     * @return string The version number of the plugin.
529     * @since     1.0.0
530     */
531    public function get_version() {
532        return $this->version;
533    }
534
535    /**
536     * Handle an environment change to set the correct status to the Critical CSS request.
537     * This is done here so even if the Critical CSS module is switched off we can
538     * still capture the change of environment event and flag Critical CSS for a rebuild.
539     */
540    public function handle_environment_change( $is_major_change, $change_type ) {
541        if ( $is_major_change ) {
542            Regenerate_Admin_Notice::enable();
543        }
544
545        jetpack_boost_ds_set( 'critical_css_suggest_regenerate', $change_type );
546    }
547
548    /**
549     * Plugin uninstallation handler. Delete all settings and cache.
550     */
551    public function uninstall() {
552        global $wpdb;
553
554        // When uninstalling, make sure all deactivation cleanups have run as well.
555        $this->deactivate();
556
557        // Delete all Jetpack Boost options.
558        //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
559        $option_names = $wpdb->get_col(
560            "
561                SELECT `option_name`
562                FROM   `$wpdb->options`
563                WHERE  `option_name` LIKE 'jetpack_boost_%';
564            "
565        );
566        //phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
567
568        foreach ( $option_names as $option_name ) {
569            delete_option( $option_name );
570        }
571
572        // Delete the last run options for the network-wide cron jobs.
573        delete_site_option( 'jetpack_boost_404_tester_last_run' );
574        delete_site_option( 'jetpack_boost_minify_cron_cache_cleanup_last_run' );
575        delete_site_option( 'jetpack_boost_minify_cache_rules_applied' );
576
577        // Delete stored Critical CSS and LCP data.
578        ( new Critical_CSS_Storage() )->clear();
579        ( new LCP_Storage() )->clear();
580
581        // Delete all transients created by boost.
582        Transient::delete_bulk();
583
584        // Clear getting started value
585        ( new Getting_Started_Entry() )->set( false );
586
587        Page_Cache_Setup::uninstall();
588    }
589}