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