Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
99.15% covered (success)
99.15%
701 / 707
78.26% covered (warning)
78.26%
18 / 23
CRAP
0.00% covered (danger)
0.00%
0 / 1
Main_Features
99.15% covered (success)
99.15%
701 / 707
78.26% covered (warning)
78.26%
18 / 23
124
0.00% covered (danger)
0.00%
0 / 1
 module_works_locally
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 get_feature_definitions
100.00% covered (success)
100.00%
426 / 426
100.00% covered (success)
100.00%
1 / 1
3
 get_plan_badges
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
7
 filter_upgrade
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
4
 get_upgrade
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
6
 is_included_in_plan
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
11
 pays_for_product
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
8
 get_switchable_plugins
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_plugin_status
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 get_plugin_override
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 1
6.02
 get_plugin_file
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
8
 get_hosting_plugin_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_hosting_plugin
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
3.58
 plugin_slug_from_path
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 is_only_my_jetpack_provider
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
11
 get_product_class_for_plugin
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
6.10
 get_module_groups
100.00% covered (success)
100.00%
53 / 53
100.00% covered (success)
100.00%
1 / 1
1
 get_hidden_modules
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
5
 get_state
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 get_install_access
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 get_features
98.11% covered (success)
98.11%
52 / 53
0.00% covered (danger)
0.00%
0 / 1
21
 get_screenshot_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_feature_manage_url
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
9.06
1<?php
2/**
3 * Static catalog of the main Jetpack features.
4 *
5 * @package automattic/my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack;
9
10use Automattic\Jetpack\Plugins_Installer;
11use Automattic\Jetpack\Status\Host;
12
13/**
14 * Describes the main Jetpack features: their copy, links and how a site owner gets each one.
15 *
16 * The descriptive fields may later come from a WordPress.com endpoint; what a feature is
17 * delivered by stays local, since only the site knows what is installed on it.
18 */
19class Main_Features {
20
21    /**
22     * A plugin is not on the site at all.
23     */
24    const PLUGIN_NOT_INSTALLED = 'not-installed';
25
26    /**
27     * A plugin is installed and switched off.
28     */
29    const PLUGIN_INACTIVE = 'inactive';
30
31    /**
32     * A plugin is installed and running.
33     */
34    const PLUGIN_ACTIVE = 'active';
35
36    /**
37     * The current user may install plugins here.
38     */
39    const INSTALLS_ALLOWED = 'allowed';
40
41    /**
42     * Nobody may install plugins here: file changes are turned off for the whole site.
43     */
44    const INSTALLS_DISABLED = 'disabled';
45
46    /**
47     * Others may install plugins here, but not the current user.
48     */
49    const INSTALLS_NOT_PERMITTED = 'not_permitted';
50
51    /**
52     * First My Jetpack release with the opt-in offline Features page.
53     *
54     * @since $$next-version$$
55     */
56    const MINIMUM_OFFLINE_FEATURES_VERSION = '6.10.0';
57
58    /**
59     * Whether module metadata proves it can run without either connection.
60     *
61     * @since 6.10.0
62     * @param string $slug Module slug.
63     * @return bool
64     */
65    public static function module_works_locally( $slug ) {
66        // Standalone module callbacks can ignore connection filters; missing metadata cannot prove local operation.
67        $details = ( new \Automattic\Jetpack\Modules() )->get( $slug );
68        return $details && ! $details['requires_connection'] && ! $details['requires_user_connection'];
69    }
70
71    /**
72     * The static feature catalog.
73     *
74     * Keyed by feature slug. `delivery` says what switches the feature: Protect ships inside
75     * Jetpack too, but its switch is its own plugin, so it sets `jetpack` false and names
76     * only that. `needs_account` repeats the feature module's "Requires User Connection" header.
77     *
78     * @return array<string, array<string, mixed>> Feature definitions keyed by feature slug.
79     */
80    public static function get_feature_definitions() {
81        // Built once per locale: the REST route asks for it on every `rest_api_init` to
82        // bound its plugin argument, and rebuilding a hundred translated strings for that
83        // is a cost every request to the site pays, not just this page.
84        static $definitions = array();
85
86        $locale = get_user_locale();
87
88        if ( isset( $definitions[ $locale ] ) ) {
89            return $definitions[ $locale ];
90        }
91
92        $definitions[ $locale ] = array(
93            'activity-log'      => array(
94                'info_url'         => 'https://jetpack.com/security/activity-log/',
95                'docs_url'         => 'https://jetpack.com/support/activity-log/',
96                'name'             => __( 'Activity Log', 'jetpack-my-jetpack' ),
97                'description'      => __( 'See what changed on your site, when it happened, and who did it.', 'jetpack-my-jetpack' ),
98                'long_description' => __( 'When something breaks, see exactly what changed and who changed it, from published posts to plugin updates and logins. Every connected site gets its 20 most recent events for free.', 'jetpack-my-jetpack' ),
99                'icon'             => 'list',
100                'admin_page'       => 'jetpack-activity-log',
101                'module'           => 'activity-log',
102                'needs_account'    => true,
103                'free_highlights'  => array(
104                    __( 'Your 20 most recent events', 'jetpack-my-jetpack' ),
105                    __( 'Who changed what, from posts to plugin updates and logins', 'jetpack-my-jetpack' ),
106                ),
107                'paid_highlights'  => array(
108                    __( '30 days of history with VaultPress Backup or Jetpack Security, a full year with Jetpack Complete', 'jetpack-my-jetpack' ),
109                    __( 'Filter events by activity type and date range', 'jetpack-my-jetpack' ),
110                ),
111                'delivery'         => array(
112                    'jetpack' => true,
113                    'plugin'  => '',
114                    'free'    => true,
115                ),
116                'plans'            => array( 'backup', 'security', 'pro', 'complete' ),
117                // The WordPress.com site feature the Activity Log package gates its paid history on.
118                'paid_feature'     => 'full-activity-log',
119            ),
120            'anti-spam'         => array(
121                'info_url'         => 'https://akismet.com/',
122                'docs_url'         => 'https://akismet.com/support/',
123                'name'             => __( 'Akismet Anti-spam', 'jetpack-my-jetpack' ),
124                'description'      => __( 'Stop comment and form spam without making visitors solve CAPTCHAs.', 'jetpack-my-jetpack' ),
125                'long_description' => __( 'Akismet filters spam out of your comments and form submissions in the background, so you stop moderating junk and visitors never have to prove they are human. When it gets one wrong, mark it and Akismet learns from your correction.', 'jetpack-my-jetpack' ),
126                'icon'             => 'comment',
127                'product'          => 'anti-spam',
128                'interstitial'     => '/add-akismet',
129                'free_highlights'  => array(
130                    __( 'Comment and form spam filtering', 'jetpack-my-jetpack' ),
131                    __( 'No CAPTCHAs for your visitors', 'jetpack-my-jetpack' ),
132                    __( 'For personal, non-commercial sites', 'jetpack-my-jetpack' ),
133                ),
134                'paid_highlights'  => array(
135                    __( 'Use it on business and commercial sites', 'jetpack-my-jetpack' ),
136                    __( 'Advanced stats and diagnostics for your spam activity', 'jetpack-my-jetpack' ),
137                    __( 'Email support', 'jetpack-my-jetpack' ),
138                ),
139                'delivery'         => array(
140                    'jetpack'     => false,
141                    'plugin'      => 'akismet',
142                    'plugin_name' => __( 'Akismet Anti-spam', 'jetpack-my-jetpack' ),
143                    'plugin_url'  => 'https://wordpress.org/plugins/akismet/',
144                    'free'        => true,
145                ),
146                'plans'            => array( 'security', 'pro', 'complete' ),
147                'paid_product'     => __( 'Jetpack Akismet Anti-spam', 'jetpack-my-jetpack' ),
148            ),
149            'backup'            => array(
150                'info_url'         => 'https://jetpack.com/backup/',
151                'docs_url'         => 'https://jetpack.com/support/backup/',
152                'name'             => __( 'VaultPress Backup', 'jetpack-my-jetpack' ),
153                'description'      => __( 'Get your site back online in one click if anything goes wrong.', 'jetpack-my-jetpack' ),
154                'long_description' => __( 'Every change you make is saved off-site as it happens, so your content and WooCommerce orders stay safe even if your host goes down. Restore your site in one click, even when it is offline.', 'jetpack-my-jetpack' ),
155                'icon'             => 'backup',
156                'product'          => 'backup',
157                // The plan decides it, whichever plugin delivers it, so its card has no switch.
158                'plan_driven'      => true,
159                'needs_account'    => true,
160                'interstitial'     => '/add-backup',
161                'setup_note'       => __( 'Backups start once you add a paid plan.', 'jetpack-my-jetpack' ),
162                'paid_highlights'  => array(
163                    __( 'Real-time backups of your files, database and WooCommerce orders', 'jetpack-my-jetpack' ),
164                    __( 'One-click restores, even from the Jetpack mobile app', 'jetpack-my-jetpack' ),
165                    __( 'Move your site to any host without a developer', 'jetpack-my-jetpack' ),
166                ),
167                'delivery'         => array(
168                    'jetpack'     => true,
169                    'plugin'      => 'jetpack-backup',
170                    'plugin_name' => __( 'Jetpack VaultPress Backup', 'jetpack-my-jetpack' ),
171                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-backup/',
172                    'free'        => false,
173                ),
174                'plans'            => array( 'security', 'pro', 'complete' ),
175                'paid_product'     => __( 'Jetpack VaultPress Backup', 'jetpack-my-jetpack' ),
176            ),
177            'blaze'             => array(
178                'info_url'         => 'https://jetpack.com/blaze/',
179                'docs_url'         => 'https://jetpack.com/support/blaze/',
180                'name'             => __( 'Blaze Ads', 'jetpack-my-jetpack' ),
181                'description'      => __( 'Put your best posts in front of new readers on WordPress.com and Tumblr.', 'jetpack-my-jetpack' ),
182                'long_description' => __( 'Turn a post or page into an ad shown across Tumblr and WordPress.com, aimed at the locations, languages and interests you choose.', 'jetpack-my-jetpack' ),
183                'icon'             => 'megaphone',
184                'admin_page'       => 'advertising',
185                'module'           => 'blaze',
186                // No plan sells Blaze, so it says how campaigns are paid for instead.
187                'pricing_notes'    => array(
188                    __( 'No subscription required', 'jetpack-my-jetpack' ),
189                    __( 'Set a budget for each campaign', 'jetpack-my-jetpack' ),
190                    __( 'Pay only for the ad views you get', 'jetpack-my-jetpack' ),
191                ),
192                'delivery'         => array(
193                    'jetpack'     => true,
194                    'plugin'      => 'blaze-ads',
195                    'plugin_name' => __( 'Blaze Ads', 'jetpack-my-jetpack' ),
196                    'plugin_url'  => 'https://wordpress.org/plugins/blaze-ads/',
197                    'free'        => false,
198                ),
199            ),
200            'boost'             => array(
201                'info_url'         => 'https://jetpack.com/boost/',
202                'docs_url'         => 'https://jetpack.com/support/jetpack-boost/',
203                'name'             => __( 'Boost', 'jetpack-my-jetpack' ),
204                'description'      => __( 'Make your site load faster in a few clicks, no developer required.', 'jetpack-my-jetpack' ),
205                'long_description' => __( 'Your pages reach visitors sooner: Boost caches them, defers non-essential JavaScript and serves resized images from a worldwide network. Mobile and desktop performance scores show you the impact of each change.', 'jetpack-my-jetpack' ),
206                'icon'             => 'trending-up',
207                'product'          => 'boost',
208                'essential'        => true,
209                'interstitial'     => '/add-boost',
210                'free_highlights'  => array(
211                    __( 'Page caching and deferred JavaScript', 'jetpack-my-jetpack' ),
212                    __( 'Resized images from a worldwide image CDN', 'jetpack-my-jetpack' ),
213                    __( 'Mobile and desktop performance scores', 'jetpack-my-jetpack' ),
214                ),
215                'paid_highlights'  => array(
216                    __( 'Critical CSS that updates automatically as your site changes', 'jetpack-my-jetpack' ),
217                    __( 'Performance history for mobile and desktop, including Core Web Vitals', 'jetpack-my-jetpack' ),
218                    __( 'Control over the quality and size of images from the image CDN', 'jetpack-my-jetpack' ),
219                ),
220                'delivery'         => array(
221                    'jetpack'     => false,
222                    'plugin'      => 'jetpack-boost',
223                    'plugin_name' => __( 'Jetpack Boost', 'jetpack-my-jetpack' ),
224                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-boost/',
225                    'free'        => true,
226                ),
227                'plans'            => array( 'pro', 'complete' ),
228                'paid_product'     => __( 'Jetpack Boost', 'jetpack-my-jetpack' ),
229            ),
230            'crm'               => array(
231                'info_url'         => 'https://jetpackcrm.com/',
232                'docs_url'         => 'https://kb.jetpackcrm.com/article-categories/getting-started/',
233                'name'             => __( 'Jetpack CRM', 'jetpack-my-jetpack' ),
234                'description'      => __( 'Keep every lead and customer in one place, right inside WordPress.', 'jetpack-my-jetpack' ),
235                'long_description' => __( 'Track leads, send quotes and invoices, and see each customer’s full history from your dashboard. Because it runs on your own site, your customer data stays yours.', 'jetpack-my-jetpack' ),
236                'icon'             => 'people',
237                'product'          => 'crm',
238                'interstitial'     => '/add-crm',
239                'free_highlights'  => array(
240                    __( 'Leads, contacts and each customer’s history', 'jetpack-my-jetpack' ),
241                    __( 'Quotes and invoices', 'jetpack-my-jetpack' ),
242                    __( 'Customer data that stays on your site', 'jetpack-my-jetpack' ),
243                ),
244                'paid_highlights'  => array(
245                    __( 'A sales dashboard, sales funnels and automations to follow up on leads', 'jetpack-my-jetpack' ),
246                    __( 'Take payments through Stripe and PayPal', 'jetpack-my-jetpack' ),
247                    __( 'Sync contacts from Gravity Forms, Contact Form 7 and Mailchimp', 'jetpack-my-jetpack' ),
248                ),
249                'delivery'         => array(
250                    'jetpack'     => false,
251                    'plugin'      => 'zero-bs-crm',
252                    'plugin_name' => __( 'Jetpack CRM', 'jetpack-my-jetpack' ),
253                    'plugin_url'  => 'https://wordpress.org/plugins/zero-bs-crm/',
254                    'free'        => true,
255                ),
256                'plans'            => array( 'pro', 'complete' ),
257                'paid_product'     => __( 'Jetpack CRM Entrepreneur', 'jetpack-my-jetpack' ),
258            ),
259            'jetpack-ai'        => array(
260                'info_url'         => 'https://jetpack.com/ai/',
261                'docs_url'         => 'https://jetpack.com/support/create-better-content-with-jetpack-ai/',
262                'name'             => __( 'Jetpack AI', 'jetpack-my-jetpack' ),
263                'description'      => __( 'Turn your ideas into ready-to-publish content without leaving the editor.', 'jetpack-my-jetpack' ),
264                'long_description' => __( 'Generate posts, tables, forms and images from a prompt, then change the tone, translate, or fix unclear sentences to make your writing easier to read. Before you publish, improve your title and create a featured image in one click.', 'jetpack-my-jetpack' ),
265                'icon'             => 'star',
266                'product'          => 'jetpack-ai',
267                'needs_account'    => true,
268                'interstitial'     => '/add-jetpack-ai',
269                'free_highlights'  => array(
270                    /* translators: %d is the number of free requests, such as 20. */
271                    sprintf( _n( '%d request to try it out', '%d requests to try it out', Products\Jetpack_Ai::FREE_REQUESTS, 'jetpack-my-jetpack' ), Products\Jetpack_Ai::FREE_REQUESTS ),
272                    __( 'Generate, rewrite and translate in the editor', 'jetpack-my-jetpack' ),
273                ),
274                'paid_highlights'  => array(
275                    /* translators: %d is the number of free requests, such as 20. */
276                    sprintf( _n( 'Keep creating after your %d free request runs out', 'Keep creating after your %d free requests run out', Products\Jetpack_Ai::FREE_REQUESTS, 'jetpack-my-jetpack' ), Products\Jetpack_Ai::FREE_REQUESTS ),
277                    __( 'Generate a logo for your site', 'jetpack-my-jetpack' ),
278                    __( 'Priority support', 'jetpack-my-jetpack' ),
279                ),
280                'delivery'         => array(
281                    'jetpack' => true,
282                    'plugin'  => '',
283                    'free'    => true,
284                ),
285                'plans'            => array( 'pro', 'complete' ),
286                'paid_product'     => __( 'Jetpack AI Assistant', 'jetpack-my-jetpack' ),
287            ),
288            'jetpack-forms'     => array(
289                'info_url'         => 'https://jetpack.com/forms/',
290                'docs_url'         => 'https://jetpack.com/support/jetpack-blocks/contact-form/',
291                'name'             => __( 'Forms', 'jetpack-my-jetpack' ),
292                'description'      => __( 'From quick contact forms to multistep surveys, everything you need is included.', 'jetpack-my-jetpack' ),
293                'long_description' => __( 'Break long forms into steps with a progress bar, and get every response by email and in your dashboard, with no limit on responses. Upgrade to add secure file uploads that keep harmful files off your server.', 'jetpack-my-jetpack' ),
294                'icon'             => 'list-bullets',
295                'product'          => 'jetpack-forms',
296                'essential'        => true,
297                'free_highlights'  => array(
298                    __( 'Unlimited responses, by email and in your dashboard', 'jetpack-my-jetpack' ),
299                    __( 'Multi-step forms with a progress bar', 'jetpack-my-jetpack' ),
300                ),
301                'paid_highlights'  => array(
302                    __( 'Secure file uploads that keep harmful files off your server', 'jetpack-my-jetpack' ),
303                    __( 'Visitors’ files stay private, visible only to you and your editors', 'jetpack-my-jetpack' ),
304                    __( 'Up to 10 files per field, 20 MB each', 'jetpack-my-jetpack' ),
305                ),
306                'delivery'         => array(
307                    'jetpack' => true,
308                    'plugin'  => '',
309                    'free'    => true,
310                ),
311                'plans'            => array( 'pro', 'complete' ),
312            ),
313            'newsletter'        => array(
314                'info_url'         => 'https://jetpack.com/newsletter/',
315                'docs_url'         => 'https://jetpack.com/support/newsletter/',
316                'name'             => __( 'Newsletter', 'jetpack-my-jetpack' ),
317                'description'      => __( 'Build your subscriber list and email your newsletter automatically.', 'jetpack-my-jetpack' ),
318                'long_description' => __( 'Every post you publish goes out by email, with no cap on subscribers or sends. New readers find you through the WordPress.com Reader, and when you’re ready, you can charge for your newsletter.', 'jetpack-my-jetpack' ),
319                'icon'             => 'envelope',
320                'product'          => 'newsletter',
321                'module'           => 'subscriptions',
322                'needs_account'    => true,
323                'free_highlights'  => array(
324                    __( 'No limit on subscribers or email sends', 'jetpack-my-jetpack' ),
325                    __( 'Import up to 100 subscribers', 'jetpack-my-jetpack' ),
326                    __( 'Subscribe forms and pop-ups to collect subscribers on your site', 'jetpack-my-jetpack' ),
327                    __( 'New subscribers from the WordPress.com Reader', 'jetpack-my-jetpack' ),
328                    /* translators: %d is the percentage fee, such as 10. */
329                    sprintf( __( 'Paid newsletter with a %d%% fee on subscriptions', 'jetpack-my-jetpack' ), 10 ),
330                ),
331                'paid_highlights'  => array(
332                    __( 'Import as many subscribers as you like', 'jetpack-my-jetpack' ),
333                    /* translators: %d is the percentage fee, such as 10. */
334                    sprintf( __( 'Paid newsletter with a %d%% fee on subscriptions', 'jetpack-my-jetpack' ), 2 ),
335                ),
336                'delivery'         => array(
337                    'jetpack' => true,
338                    'plugin'  => '',
339                    'free'    => true,
340                ),
341                'plans'            => array( 'growth', 'pro', 'complete' ),
342            ),
343            'podcast'           => array(
344                'info_url'         => 'https://jetpack.com/podcast/',
345                'docs_url'         => 'https://jetpack.com/support/jetpack-podcast/',
346                'name'             => __( 'Podcast', 'jetpack-my-jetpack' ),
347                'description'      => __( 'Start a podcast on your own site and reach listeners on every major app.', 'jetpack-my-jetpack' ),
348                'long_description' => __( 'Your show lives on your own site, so the feed, the audio and your listeners stay yours, with no separate podcast service to sign up for. Submit it to Apple Podcasts, Spotify, Pocket Casts and more, and your newsletter subscribers get new episodes too.', 'jetpack-my-jetpack' ),
349                'icon'             => 'audio',
350                'admin_page'       => 'jetpack-podcast',
351                'module'           => 'podcast',
352                'free_highlights'  => array(
353                    __( 'Unlimited episodes, each one a post on your site', 'jetpack-my-jetpack' ),
354                    __( 'A podcast feed on your own domain', 'jetpack-my-jetpack' ),
355                    __( 'Submit to Apple Podcasts, Spotify and more', 'jetpack-my-jetpack' ),
356                    __( 'New episodes go out to your newsletter subscribers and the WordPress.com Reader', 'jetpack-my-jetpack' ),
357                ),
358                'paid_highlights'  => array(
359                    __( 'Listener stats by episode, app and country', 'jetpack-my-jetpack' ),
360                    __( 'An episodes dashboard for your whole back catalog', 'jetpack-my-jetpack' ),
361                    __( 'An episode player with chapters, transcripts and soundbites', 'jetpack-my-jetpack' ),
362                    __( 'Video episodes and Podcasting 2.0 support', 'jetpack-my-jetpack' ),
363                ),
364                'delivery'         => array(
365                    'jetpack' => true,
366                    'plugin'  => '',
367                    'free'    => true,
368                ),
369                'plans'            => array( 'growth', 'pro', 'complete' ),
370            ),
371            'protect-dashboard' => array(
372                'info_url'         => 'https://jetpack.com/protect/',
373                'docs_url'         => 'https://jetpack.com/support/jetpack-protect/',
374                'name'             => __( 'Protect', 'jetpack-my-jetpack' ),
375                'description'      => __( 'Get warned about vulnerable plugins and stop login attacks on your site.', 'jetpack-my-jetpack' ),
376                'long_description' => __( 'Your WordPress version, plugins and themes are checked daily against a database of known vulnerabilities, with results in your dashboard. Login attacks are blocked automatically, and you can block specific IP addresses yourself.', 'jetpack-my-jetpack' ),
377                'icon'             => 'shield',
378                'product'          => 'protect',
379                // Not `protect`: that module is Brute Force Protection, which has its own row.
380                'module'           => Products\Protect::DASHBOARD_MODULE_NAME,
381                'essential'        => true,
382                'interstitial'     => '/add-protect',
383                'free_highlights'  => array(
384                    __( 'Daily checks for known vulnerabilities', 'jetpack-my-jetpack' ),
385                    __( 'Automatic blocking of login attacks', 'jetpack-my-jetpack' ),
386                    __( 'Block IP addresses yourself', 'jetpack-my-jetpack' ),
387                ),
388                'paid_highlights'  => array(
389                    __( 'Daily malware scanning with one-click fixes for most threats', 'jetpack-my-jetpack' ),
390                    __( 'Automatic firewall rules that block harmful requests', 'jetpack-my-jetpack' ),
391                    __( 'Instant email alerts when a threat is found', 'jetpack-my-jetpack' ),
392                ),
393                'delivery'         => array(
394                    // Never on WordPress.com Simple, whose partial bootstrap skips the module's flag.
395                    'jetpack'     => ! ( new Host() )->is_wpcom_simple() && Products\Protect::is_dashboard_module_available(),
396                    'plugin'      => 'jetpack-protect',
397                    'plugin_name' => __( 'Jetpack Protect', 'jetpack-my-jetpack' ),
398                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-protect/',
399                    'free'        => true,
400                ),
401                'plans'            => array( 'security', 'pro', 'complete' ),
402                'paid_product'     => __( 'Jetpack Scan', 'jetpack-my-jetpack' ),
403            ),
404            'search'            => array(
405                'info_url'         => 'https://jetpack.com/search/',
406                'docs_url'         => 'https://jetpack.com/support/search/',
407                'name'             => __( 'Search', 'jetpack-my-jetpack' ),
408                'description'      => __( 'Help your visitors find the right post or product as they type.', 'jetpack-my-jetpack' ),
409                'long_description' => __( 'Visitors see relevant results as they type and can filter by category, tag, date or author, so they find what they need instead of leaving. Match search to your theme without writing code.', 'jetpack-my-jetpack' ),
410                'icon'             => 'search',
411                'product'          => 'search',
412                'interstitial'     => '/add-search',
413                'setup_note'       => __( 'To start using it, choose a plan next, including a free one.', 'jetpack-my-jetpack' ),
414                'free_highlights'  => array(
415                    __( 'Up to 500 search requests per month', 'jetpack-my-jetpack' ),
416                    __( 'Results as visitors type', 'jetpack-my-jetpack' ),
417                    __( 'Filters for category, tag, date and author', 'jetpack-my-jetpack' ),
418                ),
419                'paid_highlights'  => array(
420                    __( 'Room for more records and monthly searches as your site grows', 'jetpack-my-jetpack' ),
421                    __( 'AI Answers', 'jetpack-my-jetpack' ),
422                    __( 'No Jetpack branding, plus priority support', 'jetpack-my-jetpack' ),
423                ),
424                'delivery'         => array(
425                    'jetpack'     => true,
426                    'plugin'      => 'jetpack-search',
427                    'plugin_name' => __( 'Jetpack Search', 'jetpack-my-jetpack' ),
428                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-search/',
429                    'free'        => true,
430                ),
431                'plans'            => array( 'pro', 'complete' ),
432                'paid_product'     => __( 'Jetpack Search', 'jetpack-my-jetpack' ),
433            ),
434            'social'            => array(
435                'info_url'         => 'https://jetpack.com/social/',
436                'docs_url'         => 'https://jetpack.com/support/jetpack-social/',
437                'name'             => __( 'Social', 'jetpack-my-jetpack' ),
438                'description'      => __( 'Share your posts to your social networks automatically when you publish.', 'jetpack-my-jetpack' ),
439                'long_description' => __( 'Reach your followers on Facebook, Instagram, Threads, Bluesky, LinkedIn, Mastodon, Nextdoor and Tumblr without leaving WordPress. Posts share automatically when you publish, and you can re-share or schedule them later.', 'jetpack-my-jetpack' ),
440                'icon'             => 'share',
441                'product'          => 'social',
442                'needs_account'    => true,
443                'interstitial'     => '/add-social',
444                'free_highlights'  => array(
445                    __( 'Unlimited shares', 'jetpack-my-jetpack' ),
446                    __( 'Automatic sharing when you publish', 'jetpack-my-jetpack' ),
447                    __( 'Facebook, Instagram, Threads, Bluesky, LinkedIn and more', 'jetpack-my-jetpack' ),
448                ),
449                'paid_highlights'  => array(
450                    __( 'Tailor the message and media for each network', 'jetpack-my-jetpack' ),
451                    __( 'Save reusable message templates for each account', 'jetpack-my-jetpack' ),
452                    __( 'Branded share images from Social Image Generator', 'jetpack-my-jetpack' ),
453                ),
454                'delivery'         => array(
455                    'jetpack'     => true,
456                    'plugin'      => 'jetpack-social',
457                    'plugin_name' => __( 'Jetpack Social', 'jetpack-my-jetpack' ),
458                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-social/',
459                    'free'        => true,
460                ),
461                'plans'            => array( 'growth', 'pro', 'complete' ),
462                'paid_product'     => __( 'Jetpack Social', 'jetpack-my-jetpack' ),
463            ),
464            'stats'             => array(
465                'info_url'         => 'https://jetpack.com/stats/',
466                'docs_url'         => 'https://jetpack.com/support/jetpack-stats/',
467                'name'             => __( 'Stats', 'jetpack-my-jetpack' ),
468                'description'      => __( 'See how many people visit your site and which posts they read.', 'jetpack-my-jetpack' ),
469                'long_description' => __( 'Track views, visitors, top posts, referrers and visitor countries right from your WordPress dashboard. Learn what works without seeing who your individual visitors are.', 'jetpack-my-jetpack' ),
470                'icon'             => 'chart-bar',
471                'product'          => 'stats',
472                'essential'        => true,
473                'interstitial'     => '/add-stats',
474                'free_highlights'  => array(
475                    __( 'Views, visitors and top posts', 'jetpack-my-jetpack' ),
476                    __( 'Referrers and visitor countries', 'jetpack-my-jetpack' ),
477                ),
478                'paid_highlights'  => array(
479                    __( 'UTM tracking to see which campaigns bring you traffic', 'jetpack-my-jetpack' ),
480                    __( 'Device stats to see how visitors browse your site', 'jetpack-my-jetpack' ),
481                    __( 'Region and city locations, beyond country level', 'jetpack-my-jetpack' ),
482                ),
483                'delivery'         => array(
484                    'jetpack'     => true,
485                    'plugin'      => 'jetpack-stats',
486                    'plugin_name' => __( 'Jetpack Stats', 'jetpack-my-jetpack' ),
487                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-stats/',
488                    'free'        => true,
489                ),
490                'plans'            => array( 'growth', 'pro', 'complete' ),
491                'paid_product'     => __( 'Jetpack Stats', 'jetpack-my-jetpack' ),
492            ),
493            'videopress'        => array(
494                'info_url'         => 'https://jetpack.com/videopress/',
495                'docs_url'         => 'https://jetpack.com/support/jetpack-videopress/',
496                'name'             => __( 'VideoPress', 'jetpack-my-jetpack' ),
497                'description'      => __( 'Share ad-free, high-quality video that keeps visitors on your site.', 'jetpack-my-jetpack' ),
498                'long_description' => __( 'Keep the focus on your videos with ad-free playback that fits your brand. Drag and drop videos into the WordPress editor to get started.', 'jetpack-my-jetpack' ),
499                'icon'             => 'video',
500                'product'          => 'videopress',
501                'interstitial'     => '/add-videopress',
502                'free_highlights'  => array(
503                    __( 'Host one video', 'jetpack-my-jetpack' ),
504                    __( 'Ad-free playback up to 4K', 'jetpack-my-jetpack' ),
505                    __( 'Match the player to your brand', 'jetpack-my-jetpack' ),
506                ),
507                'paid_highlights'  => array(
508                    __( 'Host unlimited videos', 'jetpack-my-jetpack' ),
509                    __( 'Up to 1TB of video storage', 'jetpack-my-jetpack' ),
510                ),
511                'delivery'         => array(
512                    'jetpack'     => true,
513                    'plugin'      => 'jetpack-videopress',
514                    'plugin_name' => __( 'Jetpack VideoPress', 'jetpack-my-jetpack' ),
515                    'plugin_url'  => 'https://wordpress.org/plugins/jetpack-videopress/',
516                    'free'        => true,
517                ),
518                'plans'            => array( 'pro', 'complete' ),
519                'paid_product'     => __( 'Jetpack VideoPress', 'jetpack-my-jetpack' ),
520            ),
521        );
522
523        return $definitions[ $locale ];
524    }
525
526    /**
527     * The paid bundles that include a feature, named for display.
528     *
529     * Named by the bundle products themselves, so the Features tab and the rest of My Jetpack
530     * call a plan the same thing.
531     *
532     * @param array $definition One feature's catalog entry.
533     * @param bool  $local      Skip ownership lookups.
534     * @return array List of slug/name/owned triples, without ownership in local mode.
535     */
536    private static function get_plan_badges( $definition, $local = false ) {
537        $badges = array();
538
539        foreach ( $definition['plans'] ?? array() as $slug ) {
540            $bundle_class = Products::get_product_class( $slug );
541
542            if ( $bundle_class && ( $local ? 'pro' !== $slug : ( $bundle_class::has_paid_plan_for_product() || ! empty( $bundle_class::get_pricing_for_ui()['available'] ) ) ) ) {
543                $badge = array(
544                    'slug' => $slug,
545                    'name' => $bundle_class::get_title(),
546                );
547                if ( ! $local ) {
548                    $badge['owned'] = $bundle_class::has_paid_plan_for_product();
549                }
550                $badges[] = $badge;
551            }
552        }
553
554        return $badges;
555    }
556
557    /**
558     * Lets a host send a feature's Upgrade button to its own plans instead of Jetpack's.
559     *
560     * @param array  $upgrade  The Jetpack route, from get_upgrade().
561     * @param string $slug     The feature slug.
562     * @param bool   $included Whether the site already pays for the feature.
563     * @return array{path: string, name: string, url?: string}
564     */
565    private static function filter_upgrade( array $upgrade, $slug, $included ) {
566        /**
567         * Filters where a My Jetpack feature's Upgrade button goes.
568         *
569         * Set `url` to an absolute address to replace the My Jetpack route, which also drops the
570         * Jetpack plans the feature's details would otherwise link to. Ignored when `$included`.
571         *
572         * @since $$next-version$$
573         *
574         * @param array  $upgrade  `path` (a My Jetpack route) and `name` (the product sold), both empty when nothing is.
575         * @param string $slug     The feature slug.
576         * @param bool   $included Whether the site already pays for the feature.
577         */
578        $filtered = apply_filters( 'jetpack_my_jetpack_feature_upgrade', $upgrade, $slug, $included );
579
580        if ( ! is_array( $filtered ) ) {
581            return $upgrade;
582        }
583
584        $result = array(
585            'path' => (string) ( $filtered['path'] ?? '' ),
586            'name' => (string) ( $filtered['name'] ?? '' ),
587        );
588
589        // A site that already pays has nothing to buy, wherever a host would send it.
590        if ( ! $included && ! empty( $filtered['url'] ) ) {
591            $result['url'] = esc_url_raw( (string) $filtered['url'] );
592        }
593
594        return $result;
595    }
596
597    /**
598     * Where the modal's Upgrade button goes: the feature's own product page, else the cheapest bundle that includes it.
599     *
600     * @param array       $definition    A single entry from the feature catalog.
601     * @param string|null $product_class The product behind the feature, when it has one.
602     * @param bool        $included      Whether the site already pays for the feature.
603     * @return array{path: string, name: string} The My Jetpack route and the product it sells, both empty when nothing does.
604     */
605    private static function get_upgrade( $definition, $product_class, $included ) {
606        $none = array(
607            'path' => '',
608            'name' => '',
609        );
610
611        // Nothing to sell a site that already pays for the feature.
612        if ( $included ) {
613            return $none;
614        }
615
616        if ( ! empty( $definition['interstitial'] ) ) {
617            return array(
618                'path' => $definition['interstitial'],
619                'name' => $definition['paid_product'] ?? '',
620            );
621        }
622
623        // Plans list the cheapest bundle first, so this sells the least a site needs to buy.
624        foreach ( $definition['plans'] ?? array() as $plan ) {
625            $bundle_class = Products::get_product_class( $plan );
626
627            if ( $bundle_class && ! empty( $bundle_class::get_pricing_for_ui()['available'] ) ) {
628                return array(
629                    'path' => '/add-' . $plan,
630                    'name' => $bundle_class::get_title(),
631                );
632            }
633        }
634
635        return $none;
636    }
637
638    /**
639     * Whether the site already pays for a feature, directly or through a bundle.
640     *
641     * @param array       $definition    A single entry from the feature catalog.
642     * @param string|null $product_class The product behind the feature, when it has one.
643     * @return bool
644     */
645    private static function is_included_in_plan( $definition, $product_class ) {
646        // An expired purchase still matches by slug; a plan-driven card offers to renew it instead.
647        $expiry_counts = ! empty( $definition['plan_driven'] );
648
649        if ( $product_class && self::pays_for_product( $product_class ) && ! ( $expiry_counts && $product_class::is_paid_plan_expired() ) ) {
650            return true;
651        }
652
653        foreach ( $definition['plans'] ?? array() as $plan ) {
654            $bundle_class = Products::get_product_class( $plan );
655
656            if ( $bundle_class && $bundle_class::has_paid_plan_for_product() && ! ( $expiry_counts && $bundle_class::is_paid_plan_expired() ) ) {
657                return true;
658            }
659        }
660
661        // Covers plans no bundle class lists, such as the legacy Jetpack Personal, Premium and Professional.
662        return ! empty( $definition['paid_feature'] ) && Product::does_site_have_feature( $definition['paid_feature'] );
663    }
664
665    /**
666     * Whether the site pays for a product, not counting the product's own free plan.
667     *
668     * @param string $product_class The product behind the feature.
669     * @return bool
670     */
671    private static function pays_for_product( $product_class ) {
672        if ( ! $product_class::has_paid_plan_for_product() ) {
673            return false;
674        }
675
676        $free_slug = $product_class::get_wpcom_free_product_slug();
677        $purchases = Wpcom_Products::get_site_current_purchases();
678        $purchases = is_array( $purchases ) ? $purchases : array();
679        $paid      = $free_slug
680            ? array_filter( $purchases, fn( $purchase ) => false === strpos( $purchase->product_slug, $free_slug ) )
681            : $purchases;
682
683        if ( count( $paid ) === count( $purchases ) ) {
684            return true;
685        }
686
687        /*
688         * A free plan such as `jetpack_search_free` matches the paid slug by substring and gets the
689         * same site feature, so only a purchase besides it counts.
690         */
691        $paid_slugs = array_merge(
692            $product_class::get_paid_bundles_that_include_product(),
693            $product_class::get_paid_plan_product_slugs()
694        );
695
696        foreach ( $paid as $purchase ) {
697            foreach ( $paid_slugs as $paid_slug ) {
698                if ( false !== strpos( $purchase->product_slug, $paid_slug ) ) {
699                    return true;
700                }
701            }
702        }
703
704        return false;
705    }
706
707    /**
708     * The plugins the Features tab may install or switch: every standalone plugin in the map,
709     * and Jetpack itself.
710     *
711     * @return string[] WordPress.org plugin slugs.
712     */
713    public static function get_switchable_plugins() {
714        $plugins = array_filter( array_column( array_column( self::get_feature_definitions(), 'delivery' ), 'plugin' ) );
715
716        return array_values( array_unique( array_merge( array( Product::JETPACK_PLUGIN_SLUG ), $plugins ) ) );
717    }
718
719    /**
720     * Whether a plugin is missing, installed and off, or running.
721     *
722     * @param string      $slug          WordPress.org plugin slug.
723     * @param string|null $product_class The product behind the plugin, when it has one.
724     * @return string One of the PLUGIN_* constants.
725     */
726    public static function get_plugin_status( $slug, $product_class = null ) {
727        $file = self::get_plugin_file( $slug, $product_class );
728
729        if ( ! $file ) {
730            return self::PLUGIN_NOT_INSTALLED;
731        }
732
733        // A network-activated plugin is running here, whatever this site's own list says.
734        return 'inactive' === Plugins_Installer::get_plugin_status( $file )
735            ? self::PLUGIN_INACTIVE
736            : self::PLUGIN_ACTIVE;
737    }
738
739    /**
740     * Whether a plugin is forced on or off where this site's own switch can't change it.
741     *
742     * Mirrors `Jetpack_Modules_Overrides`: an `option_active_plugins` filter that adds or
743     * drops the plugin whatever the stored list says, or a network activation.
744     *
745     * @since 6.6.0
746     *
747     * @param string      $slug          WordPress.org plugin slug.
748     * @param string|null $product_class The product behind the plugin, when it has one.
749     * @return string 'active' or 'inactive' when forced, or an empty string when the owner decides.
750     */
751    public static function get_plugin_override( $slug, $product_class = null ) {
752        $file = self::get_plugin_file( $slug, $product_class );
753
754        if ( ! $file ) {
755            return '';
756        }
757
758        if ( 'network-active' === Plugins_Installer::get_plugin_status( $file ) ) {
759            return self::PLUGIN_ACTIVE;
760        }
761
762        if ( ! has_filter( 'option_active_plugins' ) ) {
763            return '';
764        }
765
766        /** This filter is documented in wp-includes/option.php */
767        if ( in_array( $file, (array) apply_filters( 'option_active_plugins', array(), 'active_plugins' ), true ) ) {
768            return self::PLUGIN_ACTIVE;
769        }
770
771        /** This filter is documented in wp-includes/option.php */
772        if ( ! in_array( $file, (array) apply_filters( 'option_active_plugins', array( $file ), 'active_plugins' ), true ) ) {
773            return self::PLUGIN_INACTIVE;
774        }
775
776        return '';
777    }
778
779    /**
780     * The installed file for a plugin, by the names its product declares where there is one.
781     *
782     * Prefer an active copy when several declared folders are installed, including -dev checkouts.
783     *
784     * @param string      $slug          WordPress.org plugin slug.
785     * @param string|null $product_class The product behind the plugin, when it has one.
786     * @return string|false The plugin file, or false when it is not installed.
787     */
788    public static function get_plugin_file( $slug, $product_class = null ) {
789        if ( Product::JETPACK_PLUGIN_SLUG === $slug ) {
790            $filenames = Product::JETPACK_PLUGIN_FILENAME;
791        } elseif ( $product_class && $product_class::$has_standalone_plugin ) {
792            $filenames = $product_class::get_plugin_filename();
793        } else {
794            return Plugins_Installer::get_plugin_id_by_slug( $slug );
795        }
796
797        $plugins   = Plugins_Installer::get_plugins();
798        $installed = false;
799        foreach ( (array) $filenames as $file ) {
800            if ( ! isset( $plugins[ $file ] ) ) {
801                continue;
802            }
803            if ( $plugins[ $file ]['active'] ) {
804                return $file;
805            }
806            if ( false === $installed ) {
807                $installed = $file;
808            }
809        }
810
811        return $installed;
812    }
813
814    /**
815     * The plugin this copy of My Jetpack is running from.
816     *
817     * My Jetpack ships inside Jetpack, Boost, Protect, Social, Search and VideoPress, and
818     * whichever one wins the autoloader renders this page â€” so that is the plugin a switch
819     * here must never turn off.
820     *
821     * @return string The plugin's folder name, or an empty string when it is not under one.
822     */
823    public static function get_hosting_plugin_slug() {
824        return self::plugin_slug_from_path( WP_PLUGIN_DIR, __DIR__ );
825    }
826
827    /**
828     * Whether a plugin slug names the plugin this copy of My Jetpack runs from.
829     *
830     * Compared by folder rather than by slug: a checkout in `jetpack-protect-dev` serves
831     * the page just as well, and never equals the `jetpack-protect` a request carries.
832     *
833     * @param string $slug WordPress.org plugin slug.
834     * @return bool True when the plugin is the one this page is being served from.
835     */
836    public static function is_hosting_plugin( $slug ) {
837        $host = self::get_hosting_plugin_slug();
838
839        if ( '' === $host ) {
840            return false;
841        }
842
843        $file = self::get_plugin_file( $slug, self::get_product_class_for_plugin( $slug ) );
844
845        return $file ? dirname( (string) $file ) === $host : $host === $slug;
846    }
847
848    /**
849     * The plugin folder a path sits in.
850     *
851     * @param string $plugins_dir The plugin directory, as WP_PLUGIN_DIR gives it.
852     * @param string $path        The path to place.
853     * @return string The plugin's folder name, or an empty string when the path is outside.
854     */
855    public static function plugin_slug_from_path( $plugins_dir, $path ) {
856        $plugins_dir = wp_normalize_path( trailingslashit( $plugins_dir ) );
857        $path        = wp_normalize_path( $path );
858
859        if ( ! str_starts_with( $path, $plugins_dir ) ) {
860            return '';
861        }
862
863        $segments = explode( '/', substr( $path, strlen( $plugins_dir ) ) );
864
865        return $segments[0];
866    }
867
868    /**
869     * Whether no other active plugin can take over this My Jetpack page.
870     *
871     * @since $$next-version$$ Added the $excluded_folders parameter.
872     * @param string   $slug             The plugin's folder name.
873     * @param string[] $excluded_folders Other plugin folders being deactivated in the same request.
874     * @return bool True when no other active plugin carries a suitable My Jetpack copy.
875     */
876    public static function is_only_my_jetpack_provider( $slug, $excluded_folders = array() ) {
877        $offline = Initializer::is_offline_features_enabled();
878        $active  = array_merge(
879            (array) get_option( 'active_plugins', array() ),
880            array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) )
881        );
882
883        foreach ( $active as $file ) {
884            $folder = dirname( (string) $file );
885
886            if ( '.' === $folder || $folder === $slug || in_array( $folder, $excluded_folders, true ) ) {
887                continue;
888            }
889
890            $package = WP_PLUGIN_DIR . '/' . $folder . '/jetpack_vendor/automattic/jetpack-my-jetpack';
891            if ( ! is_dir( $package ) ) {
892                continue;
893            }
894
895            if ( ! $offline ) {
896                return false;
897            }
898
899            // Older copies cannot keep Features open offline. Read the bundled version without loading its classes.
900            $initializer = $package . '/src/class-initializer.php';
901            if ( is_file( $initializer ) && is_readable( $initializer )
902                // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local bundled PHP metadata, not a remote URL.
903                && preg_match( '/\bconst\s+PACKAGE_VERSION\s*=\s*[\'\"](\d+\.\d+\.\d+(?:[.\-+][\w.\-]+)?)[\'\"]\s*;/', file_get_contents( $initializer ), $version )
904                && version_compare( $version[1], self::MINIMUM_OFFLINE_FEATURES_VERSION, '>=' ) ) {
905                return false;
906            }
907        }
908
909        return true;
910    }
911
912    /**
913     * The product class behind a plugin in the map, for surfaces holding only its slug.
914     *
915     * @param string $slug WordPress.org plugin slug.
916     * @return string|null The product class, or null when no product ships that plugin.
917     */
918    public static function get_product_class_for_plugin( $slug ) {
919        foreach ( self::get_feature_definitions() as $definition ) {
920            if ( ( $definition['delivery']['plugin'] ?? '' ) !== $slug || ! isset( $definition['product'] ) ) {
921                continue;
922            }
923
924            $product_class = Products::get_product_class( $definition['product'] );
925
926            if ( $product_class && $product_class::$has_standalone_plugin ) {
927                return $product_class;
928            }
929        }
930
931        return null;
932    }
933
934    /**
935     * Headings for the modules the feature list does not cover.
936     *
937     * Grouped by the job a site owner is doing, not by Jetpack's module tags, which describe
938     * mechanism (the Image CDN is tagged Appearance). Anything unlisted falls into Other.
939     *
940     * @return array Groups, each with a label and its module slugs. The UI sorts both by name.
941     */
942    public static function get_module_groups() {
943        return array(
944            array(
945                'label'   => __( 'Security', 'jetpack-my-jetpack' ),
946                'modules' => array( 'account-protection', 'monitor', 'protect', 'sso', 'waf' ),
947            ),
948            array(
949                'label'   => __( 'Performance', 'jetpack-my-jetpack' ),
950                'modules' => array( 'photon', 'photon-cdn' ),
951            ),
952            array(
953                'label'   => __( 'Search engines', 'jetpack-my-jetpack' ),
954                'modules' => array( 'sitemaps', 'seo-tools', 'canonical-urls', 'verification-tools' ),
955            ),
956            array(
957                'label'   => __( 'Engagement', 'jetpack-my-jetpack' ),
958                'modules' => array(
959                    'comments',
960                    'likes',
961                    'comment-likes',
962                    'gravatar-hovercards',
963                    'related-posts',
964                    'sharedaddy',
965                    'shortlinks',
966                ),
967            ),
968            array(
969                'label'   => __( 'Writing', 'jetpack-my-jetpack' ),
970                'modules' => array(
971                    'blocks',
972                    'markdown',
973                    'latex',
974                    'shortcodes',
975                    'copy-post',
976                    'custom-content-types',
977                    'post-by-email',
978                    'post-list',
979                    'carousel',
980                    'tiled-gallery',
981                ),
982            ),
983            array(
984                'label'   => __( 'Design', 'jetpack-my-jetpack' ),
985                'modules' => array( 'google-fonts', 'widgets', 'widget-visibility' ),
986            ),
987            array(
988                'label'   => __( 'Earn', 'jetpack-my-jetpack' ),
989                'modules' => array( 'wordads' ),
990            ),
991            array(
992                'label'   => __( 'Analytics', 'jetpack-my-jetpack' ),
993                'modules' => array( 'woocommerce-analytics' ),
994            ),
995        );
996    }
997
998    /**
999     * Slugs the host has hidden, plus the module behind each hidden feature or product.
1000     *
1001     * @since 6.11.0
1002     * @return string[] Hidden module and feature slugs.
1003     */
1004    public static function get_hidden_modules() {
1005        $hidden = Feature_Visibility::get_hidden();
1006        foreach ( self::get_feature_definitions() as $slug => $definition ) {
1007            $names = array_filter( array( $slug, $definition['product'] ?? '', $definition['module'] ?? '' ) );
1008            if ( array_intersect( $names, $hidden ) ) {
1009                $product_class = isset( $definition['product'] ) ? Products::get_product_class( $definition['product'] ) : null;
1010                $hidden[]      = $definition['module'] ?? ( $product_class ? $product_class::get_module_name() : '' );
1011            }
1012        }
1013        return array_values( array_unique( array_filter( $hidden ) ) );
1014    }
1015
1016    /**
1017     * Everything the Features tab renders from: the Jetpack plugin's status, each feature, the
1018     * headings for Jetpack's other modules, and whether the current user may install plugins.
1019     *
1020     * @param bool $local Use the local feature contract documented in get_features().
1021     * @return array{jetpack: string, features: array, module_groups: array, plugin_installs: string, hidden_modules: string[]} The state.
1022     */
1023    public static function get_state( $local = false ) {
1024        return array(
1025            'jetpack'         => self::get_plugin_status( Product::JETPACK_PLUGIN_SLUG ),
1026            'features'        => self::get_features( $local ),
1027            'module_groups'   => self::get_module_groups(),
1028            'plugin_installs' => self::get_install_access(),
1029            'hidden_modules'  => self::get_hidden_modules(),
1030        );
1031    }
1032
1033    /**
1034     * Whether the current user may install plugins here, and if not, why not.
1035     *
1036     * @since 6.7.0
1037     *
1038     * @return string One of the INSTALLS_* constants.
1039     */
1040    public static function get_install_access() {
1041        if ( current_user_can( 'install_plugins' ) ) {
1042            return self::INSTALLS_ALLOWED;
1043        }
1044
1045        // Core's own map_meta_cap() check for install_plugins: DISALLOW_FILE_MODS or the file_mod_allowed filter.
1046        if ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) {
1047            return self::INSTALLS_DISABLED;
1048        }
1049
1050        return self::INSTALLS_NOT_PERMITTED;
1051    }
1052
1053    /**
1054     * The feature catalog merged with each feature's live state, sorted by name.
1055     *
1056     * @param bool $local Keep only local management URLs, set upgrade to null, and omit
1057     *                    included, setup_note, and plan owned fields without resolving ownership.
1058     * @return array List of features, each with slug, name, description, icon, manage_url,
1059     *               the plugin it ships as and the product/module join keys.
1060     */
1061    public static function get_features( $local = false ) {
1062        $features = array();
1063        $hidden   = Feature_Visibility::get_hidden();
1064
1065        foreach ( self::get_feature_definitions() as $slug => $definition ) {
1066            // A host can name the feature by its own slug or by its product's or module's.
1067            $names = array_filter( array( $slug, $definition['product'] ?? '', $definition['module'] ?? '' ) );
1068            if ( array_intersect( $names, $hidden ) ) {
1069                continue;
1070            }
1071
1072            $delivery      = $definition['delivery'] ?? array();
1073            $plugin        = $delivery['plugin'] ?? '';
1074            $product_class = isset( $definition['product'] ) ? Products::get_product_class( $definition['product'] ) : null;
1075            $included      = ! $local && self::is_included_in_plan( $definition, $product_class );
1076
1077            $feature = array(
1078                'slug'             => $slug,
1079                'name'             => $definition['name'],
1080                'description'      => $definition['description'],
1081                'long_description' => $definition['long_description'] ?? '',
1082                'icon'             => $definition['icon'],
1083                'manage_url'       => self::get_feature_manage_url( $definition, $product_class, $local ),
1084                'essential'        => ! empty( $definition['essential'] ),
1085                // An older Jetpack plugin still lets the module decide, so the card keeps its switch there.
1086                'plan_driven'      => ! empty( $definition['plan_driven'] ) && ( ! $product_class || ! method_exists( $product_class, 'is_plan_driven' ) || $product_class::is_plan_driven() ),
1087                'in_jetpack'       => $delivery['jetpack'] ?? false,
1088                'plugin'           => $plugin,
1089                'plugin_name'      => $plugin ? ( $delivery['plugin_name'] ?? $definition['name'] ) : '',
1090                'plugin_url'       => $plugin ? ( $delivery['plugin_url'] ?? '' ) : '',
1091                'plugin_status'    => $plugin ? self::get_plugin_status( $plugin, $product_class ) : self::PLUGIN_NOT_INSTALLED,
1092                'plugin_override'  => $plugin ? self::get_plugin_override( $plugin, $product_class ) : '',
1093                'free_highlights'  => $definition['free_highlights'] ?? array(),
1094                'paid_highlights'  => $definition['paid_highlights'] ?? array(),
1095                'pricing_notes'    => $definition['pricing_notes'] ?? array(),
1096                'upgrade'          => $local ? null : self::filter_upgrade( self::get_upgrade( $definition, $product_class, $included ), $slug, $included ),
1097                'included'         => $included,
1098                // Both notes tell the site what to buy next, which a site that pays already has.
1099                'setup_note'       => $included ? '' : ( $definition['setup_note'] ?? '' ),
1100                'screenshot'       => self::get_screenshot_url( $slug ),
1101                'plans'            => self::get_plan_badges( $definition, $local ),
1102                'info_url'         => $definition['info_url'],
1103                'docs_url'         => $definition['docs_url'],
1104                // Join keys: the UI reads live state from the module and plugin it names,
1105                // so the catalog never ships a status of its own.
1106                'product'          => $definition['product'] ?? '',
1107                'module'           => $definition['module'] ?? '',
1108                // Read even without Jetpack, whose module list would otherwise say so.
1109                'needs_account'    => ! empty( $definition['needs_account'] ),
1110            );
1111            if ( 'activity-log' === $slug && ! $local && true === ( Products\Pro::get_pricing_for_ui()['catalog_available'] ?? false ) ) {
1112                $feature['paid_highlights'][0] = __( '30 days of history with VaultPress Backup or Jetpack Pro, a full year with Jetpack Complete', 'jetpack-my-jetpack' );
1113            } elseif ( 'activity-log' === $slug && ! $local && false === ( Products\Security::get_pricing_for_ui()['available'] ?? null ) ) {
1114                $feature['paid_highlights'][0] = __( '30 days of history with VaultPress Backup, a full year with Jetpack Complete', 'jetpack-my-jetpack' );
1115            }
1116            if ( $local ) {
1117                unset( $feature['included'], $feature['setup_note'] );
1118            }
1119            $features[] = $feature;
1120        }
1121
1122        usort(
1123            $features,
1124            function ( $a, $b ) {
1125                return strnatcasecmp( $a['name'], $b['name'] );
1126            }
1127        );
1128
1129        return $features;
1130    }
1131
1132    /**
1133     * The feature's artwork, bundled with this package so the details window needs no third-party request.
1134     *
1135     * @param string $slug The feature's catalog slug, which names its image.
1136     * @return string URL of the image.
1137     */
1138    private static function get_screenshot_url( $slug ) {
1139        return Initializer::get_assets_url() . 'components/my-jetpack-tab-panel/features/images/' . $slug . '.webp';
1140    }
1141
1142    /**
1143     * Where an active feature lives.
1144     *
1145     * @param array       $definition    A single entry from the feature catalog.
1146     * @param string|null $product_class The product behind the feature, when it has one.
1147     * @param bool        $local         Keep local destinations without resolving ownership.
1148     * @return string Admin URL, or an empty string when the feature has nowhere to go.
1149     */
1150    private static function get_feature_manage_url( array $definition, $product_class = null, $local = false ) {
1151        if ( isset( $definition['admin_page'] ) ) {
1152            return admin_url( 'admin.php?page=' . $definition['admin_page'] );
1153        }
1154
1155        if ( $product_class ) {
1156            // Protect's normal destination depends on ownership, which is unknown offline.
1157            if ( $local && 'protect' === ( $definition['product'] ?? '' ) ) {
1158                return Products\Protect::has_protect_page() ? admin_url( 'admin.php?page=jetpack-protect' ) : '';
1159            }
1160
1161            $url = (string) $product_class::get_manage_url();
1162            if ( ! $local ) {
1163                return $url;
1164            }
1165
1166            wp_parse_str( (string) wp_parse_url( $url, PHP_URL_QUERY ), $query );
1167            return 0 === strpos( $url, admin_url() ) && 'my-jetpack' !== ( $query['page'] ?? '' ) ? $url : '';
1168        }
1169
1170        return '';
1171    }
1172}