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