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