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