Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
6.81% covered (danger)
6.81%
29 / 426
2.94% covered (danger)
2.94%
1 / 34
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Mu_Wpcom
6.82% covered (danger)
6.82%
29 / 425
2.94% covered (danger)
2.94%
1 / 34
16918.27
0.00% covered (danger)
0.00%
0 / 1
 init
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 1
56
 schedule_translation_updates
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 maybe_update_translations
0.00% covered (danger)
0.00%
0 / 60
0.00% covered (danger)
0.00%
0 / 1
420
 clear_translation_destination
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
30
 get_all_active_locales
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 load_features
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 1
12
 load_wpcom_user_features
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 1
90
 load_wpcom_sites_features
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 load_podcast
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 load_etk_features_flags
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
20
 load_etk_features
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
90
 load_newspack_blocks
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
 load_coming_soon
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
90
 load_launchpad
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 load_wpcom_rest_api_endpoints
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
 load_jetpack_mu_wpcom_settings
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
2
 load_map_block_settings
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
 load_newsletter_categories_settings
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
 unbind_focusout_on_wp_admin_bar_menu_toggle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 should_disable_comment_experience
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
90
 load_verbum_comments
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
 load_verbum_comments_admin
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 load_verbum_moderate
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 load_wpcom_simple_odyssey_stats
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 load_custom_css
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 load_wpcom_random_redirect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 load_social_links
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 set_wpcom_blog_id_script_data
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 enable_gutenberg_classic_block_deprecation_experiment
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 enable_gutenberg_react_19_experiment
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 add_jetpack_script_data_for_p2
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
42
 log2logstash
71.43% covered (warning)
71.43%
15 / 21
0.00% covered (danger)
0.00%
0 / 1
9.49
 resolve_logstash_blog_id
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
5.93
 queue_logstash_http
42.11% covered (danger)
42.11%
8 / 19
0.00% covered (danger)
0.00%
0 / 1
7.10
1<?php
2/**
3 * Enhances your site with features powered by WordPress.com
4 * This package is intended for internal use on WordPress.com sites only (simple and Atomic).
5 * Internal PT Reference: p9dueE-6jY-p2
6 *
7 * @package automattic/jetpack-mu-wpcom
8 */
9
10namespace Automattic\Jetpack;
11
12define( 'WPCOM_ADMIN_BAR_UNIFICATION', true );
13/**
14 * Jetpack_Mu_Wpcom main class.
15 */
16class Jetpack_Mu_Wpcom {
17    const PACKAGE_VERSION = '6.10.1';
18    const PKG_DIR         = __DIR__ . '/../';
19    const BASE_DIR        = __DIR__ . '/';
20    const BASE_FILE       = __FILE__;
21
22    /**
23     * Initialize the class.
24     */
25    public static function init() {
26        if ( did_action( 'jetpack_mu_wpcom_initialized' ) ) {
27            return;
28        }
29
30        // Shared code for src/features.
31        require_once self::PKG_DIR . 'src/common/index.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
32        require_once __DIR__ . '/common/fatal-error-signature.php';
33        require_once __DIR__ . '/utils.php';
34
35        // PCG confirmation probe wires its `pre_option_active_plugins`
36        // filter at mu-plugin time, before WP loads active plugins.
37        require_once __DIR__ . '/features/plugin-conflicts-guardian/probe-confirm-bootstrap.php';
38
39        // Load features that don't need any special loading considerations.
40        add_action( 'plugins_loaded', array( __CLASS__, 'load_features' ) );
41
42        // Load features that only apply to WordPress.com-connected users.
43        add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_user_features' ) );
44        add_action( 'plugins_loaded', array( __CLASS__, 'load_etk_features' ) );
45
46        // Load features that only apply to WordPress.com sites, regardless of whether the users are connected.
47        add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_sites_features' ) );
48
49        // Load ETK features flag to turn off the features in the ETK plugin.
50        // It needs higher priority than the ETK plugin.
51        add_action( 'plugins_loaded', array( __CLASS__, 'load_etk_features_flags' ), 0 );
52
53        /*
54         * Please double-check whether you really need to load your feature separately.
55         * Chances are you can just add it to the `load_features` method.
56         */
57        add_action( 'plugins_loaded', array( __CLASS__, 'load_launchpad' ), 0 );
58        add_action( 'plugins_loaded', array( __CLASS__, 'load_coming_soon' ) );
59        add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_rest_api_endpoints' ) );
60        add_action( 'plugins_loaded', array( __CLASS__, 'load_newspack_blocks' ) );
61
62        // These features run only on simple sites.
63        if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
64            add_action( 'plugins_loaded', array( __CLASS__, 'load_verbum_comments' ) );
65            add_action( 'plugins_loaded', array( __CLASS__, 'load_verbum_moderate' ) );
66            add_action( 'wp_loaded', array( __CLASS__, 'load_verbum_comments_admin' ) );
67            add_action( 'admin_menu', array( __CLASS__, 'load_wpcom_simple_odyssey_stats' ) );
68            add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_random_redirect' ) );
69            add_action( 'plugins_loaded', array( __CLASS__, 'load_podcast' ) );
70        }
71
72        // These features run only on atomic sites.
73        if ( defined( 'IS_ATOMIC' ) && IS_ATOMIC ) {
74            add_action( 'plugins_loaded', array( __CLASS__, 'load_custom_css' ) );
75            add_action( 'init', array( __CLASS__, 'schedule_translation_updates' ) );
76        }
77
78        // Unified navigation fix for changes in WordPress 6.2.
79        add_action( 'admin_enqueue_scripts', array( __CLASS__, 'unbind_focusout_on_wp_admin_bar_menu_toggle' ) );
80
81        // Load the Map block settings.
82        add_action( 'enqueue_block_assets', array( __CLASS__, 'load_jetpack_mu_wpcom_settings' ), 999 );
83
84        // Load the Map block settings.
85        add_action( 'enqueue_block_assets', array( __CLASS__, 'load_map_block_settings' ), 999 );
86
87        // Load the Newsletter category settings.
88        add_action( 'enqueue_block_assets', array( __CLASS__, 'load_newsletter_categories_settings' ), 999 );
89
90        // Load the Social Links feature.
91        add_action( 'init', array( __CLASS__, 'load_social_links' ), 30 );
92
93        // Filter to ensure JetpackScriptData.site.host and is_wpcom_platform is set, to ensure Jetpack blocks work as expected via P2.
94        add_filter( 'jetpack_public_js_script_data', array( __CLASS__, 'add_jetpack_script_data_for_p2' ), 10, 1 );
95
96        // Filter to populate JetpackScriptData.site.wpcom.blog_id with the actual WP.com blog ID.
97        add_filter( 'jetpack_admin_js_script_data', array( __CLASS__, 'set_wpcom_blog_id_script_data' ), 10, 1 );
98
99        // Allow sites with the `classic-block-inserter-support` blog sticker to insert the Classic block.
100        if ( wpcom_has_blog_sticker( 'classic-block-inserter-support', get_wpcom_blog_id() ) ) {
101            add_filter( 'wp_classic_block_supports_inserter', '__return_true' );
102        }
103
104        // Enable the `gutenberg-classic-block-deprecation` Gutenberg experiment for all sites, with an opt-out via the `disable-classic-block-deprecation` blog sticker.
105        // Both filters are needed: `default_option_` fires when the option doesn't exist in the DB, `option_` fires when it does.
106        add_filter( 'option_gutenberg-experiments', array( __CLASS__, 'enable_gutenberg_classic_block_deprecation_experiment' ) );
107        add_filter( 'default_option_gutenberg-experiments', array( __CLASS__, 'enable_gutenberg_classic_block_deprecation_experiment' ) );
108
109        // Enable the `gutenberg-react-19` Gutenberg experiment for sites with the `gutenberg-react-19` blog sticker.
110        add_filter( 'option_gutenberg-experiments', array( __CLASS__, 'enable_gutenberg_react_19_experiment' ) );
111        add_filter( 'default_option_gutenberg-experiments', array( __CLASS__, 'enable_gutenberg_react_19_experiment' ) );
112
113        /**
114         * Runs right after the Jetpack_Mu_Wpcom package is initialized.
115         *
116         * @since 0.1.2
117         */
118        do_action( 'jetpack_mu_wpcom_initialized' );
119    }
120
121    /**
122     * Schedules translation updates for Jetpack MU WPCOM.
123     *
124     * This function sets up the necessary cron jobs to ensure that translation files
125     * are regularly updated.
126     *
127     * @return void
128     */
129    public static function schedule_translation_updates() {
130        add_action( 'wpcomsh_translation_update', array( __CLASS__, 'maybe_update_translations' ) );
131
132        if ( ! wp_next_scheduled( 'wpcomsh_translation_update' ) ) {
133            wp_schedule_event( time(), 'twicedaily', 'wpcomsh_translation_update' );
134        }
135    }
136
137    /**
138     * Fetches and installs Jetpack-mu-wpcom package translations when needed.
139     */
140    public static function maybe_update_translations() {
141        global $wp_filesystem;
142        if ( ! $wp_filesystem ) {
143            require_once ABSPATH . 'wp-admin/includes/file.php';
144            WP_Filesystem();
145        }
146
147        $locales = self::get_all_active_locales();
148        if ( empty( $locales ) ) {
149            return;
150        }
151
152        $plugins_request_data              = array();
153        $plugin_language_pack_destinations = array(
154            'jetpack-mu-wpcom' => WP_LANG_DIR . '/mu-plugins/',
155            'wpcomsh'          => WP_LANG_DIR . '/mu-plugins/',
156        );
157
158        foreach ( array_keys( $plugin_language_pack_destinations ) as $plugin_slug ) {
159            $plugins_request_data[ $plugin_slug ] = array( 'version' => 'latest' );
160        }
161
162        $response = wp_remote_post(
163            'https://translate.wordpress.com/api/translations-updates/wpcom/plugins',
164            array(
165                'body'    => wp_json_encode(
166                    array(
167                        'locales' => $locales,
168                        'plugins' => $plugins_request_data,
169                    ),
170                    JSON_UNESCAPED_SLASHES
171                ),
172                'headers' => array( 'Content-Type' => 'application/json' ),
173                'timeout' => 10,
174            )
175        );
176
177        if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
178            return;
179        }
180
181        $data = json_decode( wp_remote_retrieve_body( $response ), true );
182
183        // API error, api returned but something was wrong.
184        if ( array_key_exists( 'success', $data ) && false === $data['success'] ) {
185            return;
186        }
187
188        if ( ! is_array( $data ) || ! is_array( $data['data'] ) ) {
189            return;
190        }
191
192        foreach ( $data['data'] as $plugin_name => $language_packs ) {
193            if ( ! isset( $plugin_language_pack_destinations[ $plugin_name ] ) ) {
194                continue;
195            }
196
197            $destination = $plugin_language_pack_destinations[ $plugin_name ];
198
199            foreach ( $language_packs as $translation ) {
200                $locale        = $translation['wp_locale'] ?? '';
201                $package_url   = $translation['package'] ?? '';
202                $last_modified = $translation['last_modified'] ?? '';
203
204                if ( ! $locale || ! $package_url || ! $last_modified ) {
205                    continue;
206                }
207
208                $local_po_file = "{$destination}/$plugin_name-{$locale}.po";
209                if ( file_exists( $local_po_file ) ) {
210                    $local_po_data                       = wp_get_pomo_file_data( $local_po_file );
211                    $installed_translation_revision_time = new \DateTime( $local_po_data['PO-Revision-Date'] );
212                    $new_translation_revision_time       = new \DateTime( $last_modified );
213
214                    // Skip if translation language pack is not newer than what is installed already.
215                    if ( $new_translation_revision_time <= $installed_translation_revision_time ) {
216                        continue;
217                    }
218                }
219
220                $translation_zip_file = download_url( $package_url );
221                if ( is_wp_error( $translation_zip_file ) ) {
222                    continue;
223                }
224
225                static::clear_translation_destination( $destination, $plugin_name, $locale );
226
227                $unzip_result = unzip_file( $translation_zip_file, $destination );
228                if ( is_wp_error( $unzip_result ) ) {
229                    wp_delete_file( $translation_zip_file );
230                    continue;
231                }
232
233                wp_delete_file( $translation_zip_file );
234
235            }
236        }
237    }
238
239    /**
240     * Clears the translation destination by deleting existing translation files.
241     *
242     * @param string $local_destination The local destination path.
243     * @param string $plugin_slug The plugin slug.
244     * @param string $locale The locale.
245     */
246    public static function clear_translation_destination( $local_destination, $plugin_slug, $locale ) {
247        global $wp_filesystem;
248
249        if ( ! $wp_filesystem ) {
250            require_once ABSPATH . 'wp-admin/includes/file.php';
251            WP_Filesystem();
252        }
253
254        $files = array(
255            "{$local_destination}{$plugin_slug}-{$locale}.po",
256            "{$local_destination}{$plugin_slug}-{$locale}.mo",
257            "{$local_destination}{$plugin_slug}-{$locale}.l10n.php",
258        );
259
260        $json_files = glob( "{$local_destination}{$plugin_slug}-{$locale}-*.json" );
261        if ( $json_files ) {
262            $files = array_merge( $files, $json_files );
263        }
264
265        foreach ( $files as $file ) {
266            if ( $wp_filesystem->exists( $file ) ) {
267                $wp_filesystem->delete( $file );
268            }
269        }
270    }
271
272    /**
273     * Retrieves all active locales for the site.
274     */
275    public static function get_all_active_locales() {
276        $locales = array( get_locale() );
277
278        $available_languages = get_available_languages();
279        if ( ! empty( $available_languages ) ) {
280            $locales = array_merge( $locales, $available_languages );
281        }
282        return array_values( array_unique( $locales ) );
283    }
284
285    /**
286     * Load features that don't need any special loading considerations.
287     */
288    public static function load_features() {
289        \Automattic\Jetpack\ExPlat::init();
290
291        // Please keep the features in alphabetical order.
292        require_once __DIR__ . '/features/100-year-plan/enhanced-ownership.php';
293        require_once __DIR__ . '/features/100-year-plan/locked-mode.php';
294        require_once __DIR__ . '/features/admin-color-schemes/admin-color-schemes.php';
295        require_once __DIR__ . '/features/ai-launchpad/ai-launchpad.php';
296        require_once __DIR__ . '/features/block-patterns/block-patterns.php';
297        require_once __DIR__ . '/features/blog-privacy/blog-privacy.php';
298        require_once __DIR__ . '/features/cloudflare-analytics/cloudflare-analytics.php';
299        require_once __DIR__ . '/features/code-editor/class-code-editor.php';
300        require_once __DIR__ . '/features/wpcom-blocks/code/class-code-block.php';
301        require_once __DIR__ . '/features/css-monkey-patches/index.php';
302        require_once __DIR__ . '/features/error-reporting/error-reporting.php';
303        require_once __DIR__ . '/features/first-posts-stream/first-posts-stream-helpers.php';
304        require_once __DIR__ . '/features/font-smoothing-antialiased/font-smoothing-antialiased.php';
305        require_once __DIR__ . '/features/google-analytics/google-analytics.php';
306        require_once __DIR__ . '/features/holiday-snow/class-holiday-snow.php';
307        require_once __DIR__ . '/features/launch-button/index.php';
308        require_once __DIR__ . '/features/layout-grid-usage-tracking/layout-grid-usage-tracking.php';
309        require_once __DIR__ . '/features/logo-tool/logo-tool.php';
310        require_once __DIR__ . '/features/marketplace-products-updater/class-marketplace-products-updater.php';
311        require_once __DIR__ . '/features/media/heif-support.php';
312        require_once __DIR__ . '/features/plugin-conflicts-guardian/plugin-conflicts-guardian.php';
313        require_once __DIR__ . '/features/post-categories/quick-actions.php';
314        require_once __DIR__ . '/features/post-like-from-email/post-like-from-email.php';
315        require_once __DIR__ . '/features/site-editor-dashboard-link/site-editor-dashboard-link.php';
316        require_once __DIR__ . '/features/wpcom-attachment-pages/wpcom-attachment-pages.php';
317        require_once __DIR__ . '/features/wpcom-block-editor/class-jetpack-wpcom-block-editor.php';
318        require_once __DIR__ . '/features/wpcom-block-editor/functions.editor-type.php';
319        require_once __DIR__ . '/features/wpcom-dashboard/class-wpcom-dashboard.php';
320        require_once __DIR__ . '/features/wpcom-logout/wpcom-logout.php';
321        require_once __DIR__ . '/features/wpcom-themes/wpcom-theme-fixes.php';
322        require_once __DIR__ . '/features/wpcom-post-list/wpcom-post-types-tracking.php';
323        require_once __DIR__ . '/features/wpcom-widgets/wpcom-widgets.php';
324        require_once __DIR__ . '/features/wpcom-wpadmin-page-view/wpcom-wpadmin-page-view.php';
325
326        require_once __DIR__ . '/features/write/write.php';
327
328        /*
329         * Temporarily disable client-side media processing.
330         *
331         * Client-side media processing enables cross-origin isolation (COEP/COOP headers)
332         * which can break authenticated API requests. This should be removed once client-side
333         * media processing is compatible with Dotcom's infrastructure.
334         *
335         * @see gutenberg_set_up_cross_origin_isolation() in Gutenberg's lib/media/load.php
336         * @see https://a8c.slack.com/archives/CBTN58FTJ/p1771950744814189
337         */
338        add_filter( 'wp_client_side_media_processing_enabled', '__return_false' );
339
340        // Initializers, if needed.
341        $activity_log_event_class = 'Automattic\\Jetpack\\Sync\\Activity_Log_Event';
342        if ( class_exists( $activity_log_event_class ) ) {
343            $activity_log_event_class::init();
344        }
345
346        \Marketplace_Products_Updater::init();
347        \Automattic\Jetpack\Code_Editor::setup();
348        \Automattic\Jetpack\Code_Block::setup();
349        \Automattic\Jetpack\Classic_Theme_Helper\Main::init();
350        \Automattic\Jetpack\Classic_Theme_Helper\Featured_Content::setup();
351
352        \Automattic\Jetpack\Jetpack_Mu_Wpcom\AI_Launchpad::init();
353        \Automattic\Jetpack\Jetpack_Mu_Wpcom\Holiday_Snow::init();
354        \Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Dashboard::init();
355
356        // Gets autoloaded from the Scheduled_Updates package.
357        if ( class_exists( 'Automattic\Jetpack\Scheduled_Updates' ) ) {
358            Scheduled_Updates::init();
359        }
360    }
361
362    /**
363     * Load features that only apply to WordPress.com-connected users.
364     */
365    public static function load_wpcom_user_features() {
366        // To avoid potential collisions with ETK.
367        if ( ! class_exists( 'A8C\FSE\Help_Center' ) ) {
368            require_once __DIR__ . '/features/help-center/class-help-center.php';
369        }
370
371        if ( ! is_wpcom_user() ) {
372            require_once __DIR__ . '/features/replace-site-visibility/hide-site-visibility.php';
373            return;
374        }
375        if ( ! class_exists( 'A8C\FSE\Survicate' ) ) {
376            require_once __DIR__ . '/features/survicate/class-survicate.php';
377        }
378        require_once __DIR__ . '/features/ai-assistant-banner/ai-assistant-banner.php';
379        require_once __DIR__ . '/features/html-block-restricted-tags/html-block-restricted-tags.php';
380        require_once __DIR__ . '/features/marketing/marketing.php';
381        require_once __DIR__ . '/features/pages/pages.php';
382        require_once __DIR__ . '/features/replace-site-visibility/replace-site-visibility.php';
383        require_once __DIR__ . '/features/stats/stats.php';
384        require_once __DIR__ . '/features/wpcom-admin-bar/wpcom-admin-bar.php';
385        require_once __DIR__ . '/features/wpcom-admin-interface/wpcom-admin-interface.php';
386        require_once __DIR__ . '/features/wpcom-admin-menu/wpcom-admin-menu.php';
387        require_once __DIR__ . '/features/wpcom-comments/wpcom-comments.php';
388        require_once __DIR__ . '/features/wpcom-dashboard-widgets/wpcom-dashboard-widgets.php';
389        require_once __DIR__ . '/features/wpcom-imports/wpcom-imports.php';
390        require_once __DIR__ . '/features/wpcom-locale/sync-locale-from-calypso-to-atomic.php';
391        require_once __DIR__ . '/features/wpcom-media/wpcom-media-url-upload.php';
392        require_once __DIR__ . '/features/wpcom-media/wpcom-export-media-files.php';
393        require_once __DIR__ . '/features/wpcom-options-general/options-general.php';
394        require_once __DIR__ . '/features/wpcom-plugins/wpcom-plugins.php';
395        require_once __DIR__ . '/features/wpcom-profile-settings/profile-settings-link-to-wpcom.php';
396        require_once __DIR__ . '/features/wpcom-profile-settings/profile-settings-notices.php';
397        require_once __DIR__ . '/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php';
398        require_once __DIR__ . '/features/wpcom-smart-dictation/class-wpcom-smart-dictation.php';
399        require_once __DIR__ . '/features/wpcom-content-research/class-wpcom-content-research.php';
400        require_once __DIR__ . '/features/wpcom-themes/wpcom-theme-tracking.php';
401        require_once __DIR__ . '/features/wpcom-themes/wpcom-themes.php';
402        require_once __DIR__ . '/features/wpcom-user-edit/wpcom-user-edit.php';
403
404        // Initialize Newsletter Settings so hooks like the Reading page notice
405        // are registered on Simple sites (where load-jetpack.php doesn't run).
406        // Guarded with class_exists since mu-wpcom no longer composer-requires
407        // the jetpack-newsletter package: the class is provided by the standalone
408        // Jetpack plugin on Atomic, or by the wpcom platform's bundled Jetpack
409        // source on Simple.
410        if ( class_exists( '\Automattic\Jetpack\Newsletter\Settings' ) ) {
411            // @phan-suppress-next-line PhanUndeclaredClassMethod -- class_exists guarded above; provided by sibling autoloader.
412            \Automattic\Jetpack\Newsletter\Settings::init();
413        }
414
415        // Register the Daily Writing Prompt dashboard widget, which now lives in
416        // the jetpack-newsletter package. Guarded with class_exists for the same
417        // reason as Settings above: mu-wpcom doesn't composer-require the package.
418        if ( class_exists( '\Automattic\Jetpack\Newsletter\Writing_Prompt_Widget' ) ) {
419            // @phan-suppress-next-line PhanUndeclaredClassMethod -- class_exists guarded above; provided by sibling autoloader.
420            \Automattic\Jetpack\Newsletter\Writing_Prompt_Widget::init();
421        }
422
423        // Only load the Masterbar features on WoA sites.
424        if ( class_exists( '\Automattic\Jetpack\Status\Host' ) && ( new \Automattic\Jetpack\Status\Host() )->is_woa_site() ) {
425            // This is temporary. After we cleanup Masterbar on WPCOM we should load Masterbar for Simple sites too.
426            \Automattic\Jetpack\Masterbar\Main::init();
427        }
428
429        if ( class_exists( 'Automattic\Jetpack\Agents_Manager\Agents_Manager' ) ) {
430            \Automattic\Jetpack\Agents_Manager\Agents_Manager::init();
431        }
432    }
433
434    /**
435     * Load features that only apply to WordPress.com sites, regardless of whether the users are connected.
436     */
437    public static function load_wpcom_sites_features() {
438        if ( is_fully_managed_agency_site() ) {
439            return;
440        }
441
442        require_once __DIR__ . '/features/gutenberg-rtc/gutenberg-rtc.php';
443        require_once __DIR__ . '/features/wpcom-contact-form-flags/wpcom-contact-form-flags.php';
444    }
445
446    /**
447     * Load the Podcast module on Simple sites.
448     *
449     * Atomic and self-hosted load Podcast through the Jetpack module system
450     * (Jetpack::late_initialization). Simple doesn't boot that Jetpack class, so
451     * initialize the module directly here.
452     */
453    public static function load_podcast() {
454        \Automattic\Jetpack\Podcast\Podcast::init();
455    }
456
457    /**
458     * Define the flags to turn off features in the ETK plugin.
459     * Can be removed once the feature no longer exists in the ETK plugin.
460     */
461    public static function load_etk_features_flags() {
462        // Don't load on agency sites.
463        if ( is_fully_managed_agency_site() ) {
464            return;
465        }
466
467        // Don't load if the user is not a wpcom user on WP Admin.
468        // The features is still required on the frontend page regardless of the user.
469        if ( is_admin() && ! is_wpcom_user() ) {
470            return;
471        }
472
473        define( 'MU_WPCOM_COBLOCKS_GALLERY', true );
474        define( 'MU_WPCOM_CUSTOM_LINE_HEIGHT', true );
475        define( 'MU_WPCOM_BLOCK_INSERTER_MODIFICATIONS', true );
476        define( 'MU_WPCOM_HOMEPAGE_TITLE_HIDDEN', true );
477        define( 'MU_WPCOM_JETPACK_GLOBAL_STYLES', true );
478        define( 'A8C_USE_FONT_SMOOTHING_ANTIALIASED', false );
479        define( 'MU_WPCOM_MAILERLITE_WIDGET', true );
480        define( 'MU_WPCOM_OVERRIDE_PREVIEW_BUTTON_URL', true );
481        define( 'MU_WPCOM_PARAGRAPH_BLOCK', true );
482        define( 'MU_WPCOM_STARTER_PAGE_TEMPLATES', true );
483        define( 'MU_WPCOM_TAGS_EDUCATION', true );
484        define( 'MU_WPCOM_BLOCK_DESCRIPTION_LINKS', true );
485        define( 'MU_WPCOM_BLOCK_EDITOR_NUX', true );
486        define( 'MU_WPCOM_POSTS_LIST_BLOCK', true );
487        define( 'MU_WPCOM_JETPACK_COUNTDOWN_BLOCK', true );
488        define( 'MU_WPCOM_JETPACK_TIMELINE_BLOCK', true );
489        define( 'MU_WPCOM_DOCUMENTATION_LINKS', true );
490        define( 'MU_WPCOM_GLOBAL_STYLES', true );
491        define( 'MU_WPCOM_FSE', true );
492        define( 'MU_WPCOM_TEMPLATE_INSERTER', true );
493        define( 'MU_WPCOM_WHATS_NEW', true );
494    }
495
496    /**
497     * Load ETK features.
498     * Can be moved back to load_features() once the feature no longer exists in the ETK plugin.
499     */
500    public static function load_etk_features() {
501        // Don't load on agency sites.
502        if ( is_fully_managed_agency_site() ) {
503            return;
504        }
505
506        // Don't load if the user is not a wpcom user on WP Admin.
507        // The features is still required on the frontend page regardless of the user.
508        if ( is_admin() && ! is_wpcom_user() ) {
509            return;
510        }
511
512        require_once __DIR__ . '/features/jetpack-global-styles/class-global-styles.php';
513        require_once __DIR__ . '/features/mailerlite/subscriber-popup.php';
514        require_once __DIR__ . '/features/wpcom-fse/wpcom-fse.php';
515
516        /**
517         * Load features for the editor and the frontend pages.
518         */
519        global $pagenow;
520        $allowed_pages = array( 'post.php', 'post-new.php', 'site-editor.php' );
521        if ( ( isset( $pagenow ) && in_array( $pagenow, $allowed_pages, true ) ) || ! is_admin() ) {
522            require_once __DIR__ . '/features/block-editor/custom-line-height.php';
523            require_once __DIR__ . '/features/block-inserter-modifications/block-inserter-modifications.php';
524            require_once __DIR__ . '/features/hide-homepage-title/hide-homepage-title.php';
525            require_once __DIR__ . '/features/override-preview-button-url/override-preview-button-url.php';
526            require_once __DIR__ . '/features/paragraph-block-placeholder/paragraph-block-placeholder.php';
527            require_once __DIR__ . '/features/tags-education/tags-education.php';
528            require_once __DIR__ . '/features/wpcom-block-description-links/wpcom-block-description-links.php';
529            require_once __DIR__ . '/features/wpcom-block-editor-nux/class-wpcom-block-editor-nux.php';
530            require_once __DIR__ . '/features/wpcom-blocks/a8c-posts-list/a8c-posts-list.php';
531            require_once __DIR__ . '/features/wpcom-blocks/event-countdown/event-countdown.php';
532            require_once __DIR__ . '/features/wpcom-blocks/timeline/timeline.php';
533            require_once __DIR__ . '/features/wpcom-documentation-links/wpcom-documentation-links.php';
534            require_once __DIR__ . '/features/wpcom-global-styles/index.php';
535            require_once __DIR__ . '/features/wpcom-legacy-fse/wpcom-legacy-fse.php';
536        } elseif ( isset( $pagenow ) && 'customize.php' === $pagenow ) {
537            // Load wpcom-global-styles on the customizer so access to additional css can be checked there.
538            require_once __DIR__ . '/features/wpcom-global-styles/index.php';
539        }
540    }
541
542    /**
543     * Load the newspack blocks feature for the editor and the frontend pages.
544     */
545    public static function load_newspack_blocks() {
546        /**
547         * Avoid potential collisions with newspack-blocks plugin.
548         */
549        if ( class_exists( '\Newspack_Blocks', false ) ) {
550            return;
551        }
552
553        global $pagenow;
554        $allowed_pages = array( 'post.php', 'post-new.php', 'site-editor.php' );
555        if ( ( isset( $pagenow ) && in_array( $pagenow, $allowed_pages, true ) ) || ! is_admin() ) {
556            define( 'MU_WPCOM_NEWSPACK_BLOCKS', true );
557            require_once __DIR__ . '/features/newspack-blocks/index.php';
558        }
559    }
560
561    /**
562     * Load the Coming Soon feature.
563     */
564    public static function load_coming_soon() {
565        /**
566         * On WoA sites, users may be using non-symlinked older versions of the FSE plugin.
567         * If they are, check the active version to avoid redeclaration errors.
568         */
569        if ( ! function_exists( 'is_plugin_active' ) ) {
570            require_once ABSPATH . 'wp-admin/includes/plugin.php';
571        }
572
573        /**
574         * Explicitly pass $markup = false in get_plugin_data to avoid indirectly calling wptexturize that could cause unintended side effects.
575         * See: https://developer.wordpress.org/reference/functions/get_plugin_data/
576         */
577        $fse_plugin                 = 'full-site-editing/full-site-editing-plugin.php';
578        $fse_plugin_path            = WP_PLUGIN_DIR . '/' . $fse_plugin;
579        $invalid_fse_version_active =
580            file_exists( $fse_plugin_path ) &&
581            is_file( $fse_plugin_path ) &&
582            is_plugin_active( $fse_plugin ) &&
583            version_compare( get_plugin_data( $fse_plugin_path, false )['Version'], '3.56084', '<' );
584
585        if ( $invalid_fse_version_active ) {
586            return;
587        }
588
589        if (
590            ( defined( 'WPCOM_PUBLIC_COMING_SOON' ) && WPCOM_PUBLIC_COMING_SOON ) ||
591            apply_filters( 'a8c_enable_public_coming_soon', false )
592        ) {
593            require_once __DIR__ . '/features/coming-soon/coming-soon.php';
594        }
595    }
596
597    /**
598     * Load the Launchpad feature.
599     */
600    public static function load_launchpad() {
601        require_once __DIR__ . '/features/launchpad/launchpad.php';
602    }
603
604    /**
605     * Load WP REST API plugins for wpcom.
606     */
607    public static function load_wpcom_rest_api_endpoints() {
608        if ( ! function_exists( 'wpcom_rest_api_v2_load_plugin' ) ) {
609            return;
610        }
611
612        // We don't use `wpcom_rest_api_v2_load_plugin_files` because it operates inconsisently.
613        $plugins = glob( __DIR__ . '/features/wpcom-endpoints/*.php' );
614
615        if ( ! is_array( $plugins ) ) {
616            return;
617        }
618
619        foreach ( array_filter( $plugins, 'is_file' ) as $plugin ) {
620            require_once $plugin;
621        }
622    }
623
624    /**
625     * Adds a global variable containing the config of the plugin to the window object.
626     */
627    public static function load_jetpack_mu_wpcom_settings() {
628        $handle = 'jetpack-mu-wpcom-settings';
629
630        // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
631        wp_register_script(
632            $handle,
633            false,
634            array(),
635            true
636        );
637
638        $data = wp_json_encode(
639            array(
640                'assetsUrl' => plugins_url( 'build/', self::BASE_FILE ),
641            ),
642            JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
643        );
644
645        wp_add_inline_script(
646            $handle,
647            "var JETPACK_MU_WPCOM_SETTINGS = $data;",
648            'before'
649        );
650
651        wp_enqueue_script( $handle );
652    }
653
654    /**
655     * Adds a global variable containing the map provider in a map_block_settings object to the window object.
656     */
657    public static function load_map_block_settings() {
658        if (
659            ! function_exists( 'get_current_screen' )
660            || \get_current_screen() === null
661        ) {
662            return;
663        }
664
665        // Return early if we are not in the block editor.
666        if ( ! wp_should_load_block_editor_scripts_and_styles() ) {
667            return;
668        }
669
670        $map_provider = apply_filters( 'wpcom_map_block_map_provider', 'mapbox' );
671        wp_localize_script( 'jetpack-blocks-editor', 'Jetpack_Maps', array( 'provider' => $map_provider ) );
672    }
673
674    /**
675     * Adds a global variable containing where the newsletter categories should be shown.
676     */
677    public static function load_newsletter_categories_settings() {
678        if (
679            ! function_exists( 'get_current_screen' )
680            || \get_current_screen() === null
681        ) {
682            return;
683        }
684
685        // Return early if we are not in the block editor.
686        if ( ! wp_should_load_block_editor_scripts_and_styles() ) {
687            return;
688        }
689
690        $newsletter_categories_location = apply_filters( 'wpcom_newsletter_categories_location', 'block' );
691        wp_localize_script( 'jetpack-blocks-editor', 'Jetpack_Subscriptions', array( 'newsletter_categories_location' => $newsletter_categories_location ) );
692    }
693
694    /**
695     * Unbinds focusout event handler on #wp-admin-bar-menu-toggle introduced in WordPress 6.2.
696     *
697     * The focusout event handler is preventing the unified navigation from being closed on mobile.
698     */
699    public static function unbind_focusout_on_wp_admin_bar_menu_toggle() {
700        wp_add_inline_script( 'common', '(function($){ $(document).on("wp-responsive-activate", function(){ $(".is-nav-unification #wp-admin-bar-menu-toggle, .is-nav-unification #adminmenumain").off("focusout"); } ); }(jQuery) );' );
701    }
702
703    /**
704     * Determine whether to disable the comment experience.
705     *
706     * @param int $blog_id The blog ID.
707     * @return boolean
708     */
709    private static function should_disable_comment_experience( $blog_id ) {
710        $path_wp_for_teams = WP_CONTENT_DIR . '/lib/wpforteams/functions.php';
711
712        if ( file_exists( $path_wp_for_teams ) ) {
713            require_once $path_wp_for_teams;
714        }
715
716        // This covers both P2 and P2020 themes.
717        $is_p2     = str_contains( get_stylesheet(), 'pub/p2' ) || function_exists( '\WPForTeams\is_wpforteams_site' ) && is_wpforteams_site( $blog_id );
718        $is_forums = str_contains( get_stylesheet(), 'a8c/supportforums' ); // Not in /forums.
719
720        $verbum_option_enabled = get_blog_option( $blog_id, 'enable_verbum_commenting', true );
721
722        if ( empty( $verbum_option_enabled ) ) {
723            return true;
724        }
725
726        // Don't load any comment experience in the Reader, GlotPress, wp-admin, or P2.
727        return ( 1 === $blog_id || TRANSLATE_BLOG_ID === $blog_id || is_admin() || $is_p2 || $is_forums );
728    }
729
730    /**
731     * Load Verbum Comments.
732     */
733    public static function load_verbum_comments() {
734        if ( class_exists( 'Verbum_Comments' ) ) {
735            return;
736        } else {
737            $blog_id = get_current_blog_id();
738            // Jetpack loads Verbum though an iframe from jetpack.wordpress.com.
739            // So we need to check the GET request for the blogid.
740            // phpcs:ignore WordPress.Security.NonceVerification.Recommended
741            if ( isset( $_GET['blogid'] ) ) {
742                $blog_id = intval( $_GET['blogid'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
743            }
744            if ( self::should_disable_comment_experience( $blog_id ) ) {
745                return;
746            }
747            require_once __DIR__ . '/features/verbum-comments/class-verbum-comments.php';
748            new \Automattic\Jetpack\Verbum_Comments();
749        }
750    }
751
752    /**
753     * Load Verbum Comments Settings.
754     */
755    public static function load_verbum_comments_admin() {
756        require_once __DIR__ . '/features/verbum-comments/assets/class-verbum-admin.php';
757        new \Automattic\Jetpack\Verbum_Admin();
758    }
759
760    /**
761     * Load Verbum Moderate.
762     */
763    public static function load_verbum_moderate() {
764        require_once __DIR__ . '/features/verbum-comments/assets/class-verbum-moderate.php';
765        new \Automattic\Jetpack\Verbum_Moderate();
766    }
767
768    /**
769     * Load Odyssey Stats in Simple sites.
770     */
771    public static function load_wpcom_simple_odyssey_stats() {
772        require_once __DIR__ . '/features/wpcom-simple-odyssey-stats/wpcom-simple-odyssey-stats.php';
773    }
774
775    /**
776     * Load the Jetpack Custom CSS feature.
777     */
778    public static function load_custom_css() {
779        require_once __DIR__ . '/features/custom-css/custom-css/preprocessors.php';
780        require_once __DIR__ . '/features/custom-css/custom-css.php';
781    }
782
783    /**
784     * Load the Random Redirect feature.
785     */
786    public static function load_wpcom_random_redirect() {
787        require_once __DIR__ . '/features/random-redirect/random-redirect.php';
788    }
789
790    /**
791     * Load the Social Links feature.
792     */
793    public static function load_social_links() {
794        if ( class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Social_Links' ) ) {
795            new \Automattic\Jetpack\Classic_Theme_Helper\Social_Links();
796        }
797    }
798
799    /**
800     * Populate JetpackScriptData.site.wpcom.blog_id with the actual WP.com blog ID.
801     *
802     * @param array $data The script data.
803     * @return array
804     */
805    public static function set_wpcom_blog_id_script_data( $data ) {
806        $blog_id = get_wpcom_blog_id();
807        if ( $blog_id ) {
808            $data['site']['wpcom']['blog_id'] = $blog_id;
809        }
810        return $data;
811    }
812
813    /**
814     * Add `gutenberg-classic-block-deprecation` to the list of enabled Gutenberg experiments.
815     * Skip sites that have the `disable-classic-block-deprecation` sticker enabled.
816     *
817     * @param mixed $experiments The current value of the gutenberg-experiments option.
818     * @return mixed Original option value or the filtered experiments.
819     */
820    public static function enable_gutenberg_classic_block_deprecation_experiment( $experiments ) {
821        if ( wpcom_has_blog_sticker( 'disable-classic-block-deprecation', get_wpcom_blog_id() ) ) {
822            return $experiments;
823        }
824
825        if ( ! is_array( $experiments ) ) {
826            $experiments = array();
827        }
828
829        $experiments['gutenberg-classic-block-deprecation'] = true;
830        return $experiments;
831    }
832
833    /**
834     * Add `gutenberg-react-19` to the list of enabled Gutenberg experiments.
835     * Only sites with the `gutenberg-react-19` blog sticker are opted in.
836     *
837     * @param mixed $experiments The current value of the gutenberg-experiments option.
838     * @return mixed Original option value or the filtered experiments.
839     */
840    public static function enable_gutenberg_react_19_experiment( $experiments ) {
841        if ( ! wpcom_has_blog_sticker( 'gutenberg-react-19', get_wpcom_blog_id() ) ) {
842            return $experiments;
843        }
844
845        if ( ! is_array( $experiments ) ) {
846            $experiments = array();
847        }
848
849        $experiments['gutenberg-react-19'] = true;
850        return $experiments;
851    }
852
853    /**
854     * Add Jetpack script data with host information on P2
855     *
856     * @param array $data - The Jetpack script data.
857     * @return array - The modified Jetpack script data.
858     */
859    public static function add_jetpack_script_data_for_p2( $data ) {
860        if (
861        str_contains( get_stylesheet(), 'pub/p2' ) ||
862        ( function_exists( '\WPForTeams\is_wpforteams_site' ) && is_wpforteams_site( get_current_blog_id() ) )
863        ) {
864            $host = new \Automattic\Jetpack\Status\Host();
865            if ( ! isset( $data['site']['host'] ) ) {
866                $data['site']['host'] = $host->get_known_host_guess();
867            }
868            if ( ! isset( $data['site']['is_wpcom_platform'] ) ) {
869                $data['site']['is_wpcom_platform'] = $host->is_wpcom_platform();
870            }
871        }
872        return $data;
873    }
874
875    /**
876     * Emit an event to the wpcom logstash cluster.
877     *
878     * Uses the in-process `log2logstash()` on WP.com Simple, and falls back to
879     * the public-api `/rest/v1.1/logstash` endpoint (fire-and-forget) on
880     * Atomic, where `log2logstash()` isn't available.
881     *
882     * Best-effort: a logging failure must never escalate into a fatal for the caller.
883     *
884     * @param string $feature Logstash `feature` bucket; should start with the `atomic_` prefix (e.g. "atomic_plugin_conflicts_guardian").
885     * @param string $message Event message slug.
886     * @param array  $extra   Event-specific properties; JSON-encoded into the `extra` field.
887     * @return void
888     */
889    public static function log2logstash( $feature, $message, array $extra = array() ) {
890        // Resolve the dispatch path once per request — on upgrade flows this
891        // can be called several times in a row (one per plugin) and the path
892        // doesn't change mid-request.
893        static $dispatch = null;
894        if ( null === $dispatch ) {
895            try {
896                if ( ! function_exists( 'log2logstash' ) ) {
897                    $log2logstash_path = WP_CONTENT_DIR . '/lib/log2logstash/log2logstash.php';
898                    if ( is_readable( $log2logstash_path ) ) {
899                        require_once $log2logstash_path;
900                    }
901                }
902            } catch ( \Throwable $e ) { // require_once can still throw (parse error / top-level fatal in the included file); fall through to the HTTP dispatch.
903                unset( $e );
904            }
905            $dispatch = function_exists( 'log2logstash' ) ? 'native' : 'http';
906        }
907
908        try {
909            $payload = array(
910                'blog_id' => self::resolve_logstash_blog_id(),
911                'feature' => (string) $feature,
912                'message' => (string) $message,
913                'extra'   => wp_json_encode( $extra, JSON_UNESCAPED_SLASHES ),
914            );
915
916            if ( 'native' === $dispatch ) {
917                log2logstash( $payload );
918                return;
919            }
920
921            // Defer the HTTP POST to shutdown. Dispatching inline as a
922            // non-blocking request loses the event when the caller `exit`s
923            // or `wp_safe_redirect`s right after (e.g. the activation-guard
924            // block path), because the cURL handle is torn down before the
925            // TLS handshake completes. Draining at shutdown with a blocking
926            // POST guarantees delivery without adding latency to the
927            // user-visible response.
928            self::queue_logstash_http( $payload );
929        } catch ( \Throwable $e ) { // best-effort: a logging failure must never escalate into a fatal for the caller.
930            unset( $e );
931        }
932    }
933
934    /**
935     * Resolve the WP.com blog ID for a logstash record.
936     *
937     * `get_wpcom_blog_id()` falls back to `get_current_blog_id()` on Atomic
938     * when `jetpack_options['id']` isn't readable — that returns `1` on a
939     * single-site install, which is a valid-looking but wrong WP.com blog ID
940     * and makes log records impossible to attribute. Emit `0` instead when
941     * the real WP.com blog ID is unknown, so the gap is obvious in Kibana.
942     *
943     * @return int WP.com blog ID, or 0 when it can't be determined.
944     */
945    private static function resolve_logstash_blog_id() {
946        // WP.com Simple: the current blog ID *is* the WP.com blog ID.
947        if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
948            return (int) get_current_blog_id();
949        }
950        // Atomic / connected Jetpack: the WP.com blog ID lives in the
951        // `jetpack_options` option. Read it directly (no `Jetpack_Options`
952        // dependency) and return 0 — never the local blog ID — when absent.
953        $jetpack_options = get_option( 'jetpack_options' );
954        if ( is_array( $jetpack_options ) && ! empty( $jetpack_options['id'] ) ) {
955            return (int) $jetpack_options['id'];
956        }
957        return 0;
958    }
959
960    /**
961     * Append a logstash payload to the shutdown drain queue, registering
962     * the drain hook on first enqueue. See `log2logstash()` for why
963     * dispatch is deferred.
964     *
965     * @param array $payload Logstash record (`blog_id`, `feature`, `message`, `extra`).
966     * @return void
967     */
968    private static function queue_logstash_http( array $payload ) {
969        static $queue = null;
970        if ( null === $queue ) {
971            $queue = array();
972            register_shutdown_function(
973                static function () use ( &$queue ) {
974                    foreach ( $queue as $entry ) {
975                        try {
976                            wp_remote_post(
977                                'https://public-api.wordpress.com/rest/v1.1/logstash',
978                                array(
979                                    'body'    => array( 'params' => wp_json_encode( $entry, JSON_UNESCAPED_SLASHES ) ),
980                                    'timeout' => 5,
981                                )
982                            );
983                        } catch ( \Throwable $e ) { // best-effort: a logging failure must never escalate into a fatal at shutdown.
984                            unset( $e );
985                        }
986                    }
987                    $queue = array();
988                }
989            );
990        }
991        $queue[] = $payload;
992    }
993}