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