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