Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
89.31% covered (warning)
89.31%
309 / 346
71.43% covered (warning)
71.43%
45 / 63
CRAP
0.00% covered (danger)
0.00%
0 / 1
Product
89.31% covered (warning)
89.31%
309 / 346
71.43% covered (warning)
71.43%
45 / 63
229.76
0.00% covered (danger)
0.00%
0 / 1
 get_plugin_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_plugin_filename
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 register_endpoints
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_ai_assistant_feature
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_wpcom_free_product_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_installed_plugin_filename
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
7
 get_info
96.88% covered (success)
96.88%
31 / 32
0.00% covered (danger)
0.00%
0 / 1
2
 get_related_plan_slugs
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 get_wpcom_info
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
4
 get_site_features_from_wpcom
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
7
 reset_site_features_cache
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 does_site_have_feature
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
5.05
 get_name
n/a
0 / 0
n/a
0 / 0
0
 get_title
n/a
0 / 0
n/a
0 / 0
0
 get_description
n/a
0 / 0
n/a
0 / 0
0
 get_long_description
n/a
0 / 0
n/a
0 / 0
0
 get_tiers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_features
n/a
0 / 0
n/a
0 / 0
0
 get_features_by_tier
n/a
0 / 0
n/a
0 / 0
1
 get_pricing_for_ui
n/a
0 / 0
n/a
0 / 0
0
 get_bundle_pricing
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
13
 get_purchase_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_host_purchase_url
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 get_manage_url
n/a
0 / 0
n/a
0 / 0
0
 get_manage_urls_by_feature
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_post_activation_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_post_checkout_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_post_checkout_urls_by_feature
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_wpcom_product_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_disclaimers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_standalone_info
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 has_paid_plan_for_product
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
9
 has_free_plan_for_product
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 has_any_plan_for_product
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 get_paid_plan_product_slugs
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_paid_bundles_that_include_product
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
5.01
 get_paid_plan_purchase_for_product
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
7
 get_paid_plan_expiration_date
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 get_paid_plan_expiration_status
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 is_paid_plan_expired
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 is_paid_plan_expiring
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_manage_paid_plan_purchase_url
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 get_renew_paid_plan_purchase_url
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 has_trial_support
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_upgradable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 is_bundle_product
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_upgradable_by_bundle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_supported_products
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_owned
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
6
 get_status
81.58% covered (warning)
81.58%
31 / 38
0.00% covered (danger)
0.00%
0 / 1
47.03
 is_active
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
4
 is_held_off
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_activated
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_plugin_installed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_plugin_active
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_jetpack_plugin_installed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_jetpack_plugin_active
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_module_active
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 get_module_name
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 activate_plugin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 do_activation
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 1
7.03
 should_use_standalone_plugin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 activate
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 do_product_specific_activation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 deactivate
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_plugin_actions_links
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
2
 filter_action_links
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 extend_plugin_action_links
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 extend_core_plugin_action_links
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 install_and_activate_standalone
40.00% covered (danger)
40.00%
4 / 10
0.00% covered (danger)
0.00%
0 / 1
10.40
 does_module_need_attention
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Base product
4 *
5 * @package my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack;
9
10use Automattic\Jetpack\Connection\Client;
11use Automattic\Jetpack\Connection\Manager as Connection_Manager;
12use Automattic\Jetpack\Modules;
13use Automattic\Jetpack\Plugins_Installer;
14use Automattic\Jetpack\Status;
15use Automattic\Jetpack\Status\Host;
16use Jetpack_Options;
17use WP_Error;
18
19/**
20 * Class responsible for handling the products
21 */
22abstract class Product {
23
24    /**
25     * The product slug
26     *
27     * @var string
28     */
29    public static $slug = null;
30
31    /**
32     * The Jetpack module name, if any.
33     *
34     * @var ?string
35     */
36    public static $module_name = null;
37
38    /**
39     * The filename (id) of the plugin associated with this product. Can be a string with a single value or a list of possible values
40     *
41     * @var string|string[]
42     */
43    public static $plugin_filename = null;
44
45    /**
46     * The slug of the plugin associated with this product. If not defined, it will default to the Jetpack plugin
47     *
48     * @var string
49     */
50    public static $plugin_slug = null;
51
52    /**
53     * The category of the product in the Jetpack ecosystem. The options are performance, growth, security, management, and create
54     *
55     * @var string
56     */
57    public static $category = null;
58
59    /**
60     * The Jetpack plugin slug
61     *
62     * @var string
63     */
64    const JETPACK_PLUGIN_SLUG = 'jetpack';
65
66    /**
67     * The Jetpack plugin filename
68     *
69     * @var array
70     */
71    const JETPACK_PLUGIN_FILENAME = array(
72        'jetpack/jetpack.php',
73        'jetpack-dev/jetpack.php',
74    );
75
76    /**
77     * The duration of time after the plan expiration date that we stop showing the plan status as "expired".
78     *
79     * @var string
80     */
81    const EXPIRATION_CUTOFF_TIME = '+2 months';
82
83    /**
84     * Transient key for storing site features
85     *
86     * @var string;
87     */
88    const MY_JETPACK_SITE_FEATURES_TRANSIENT_KEY = 'my-jetpack-site-features';
89
90    /**
91     * How long, in seconds, a site features lookup is reused before WPCOM is asked again
92     *
93     * @var int
94     */
95    const MY_JETPACK_SITE_FEATURES_CACHE_DURATION = 15;
96
97    /**
98     * A failed site features lookup, kept so one outage does not fire a request per product
99     *
100     * @var WP_Error|null
101     */
102    private static $site_features_failure = null;
103
104    /**
105     * Unix time at which the memoized failure above stops being used
106     *
107     * @var int
108     */
109    private static $site_features_failure_expires = 0;
110
111    /**
112     * The host's answer for each product get_wpcom_info() is describing, wrapped so a null answer counts.
113     *
114     * @var array<string, array{0: ?string}>
115     */
116    private static $host_purchase_urls = array();
117
118    /**
119     * A successful site features lookup, kept so one WPCOM request serves a whole render
120     * even when the transient write does not retain (e.g. an object cache evicting under load)
121     *
122     * @var array|null
123     */
124    private static $site_features_success = null;
125
126    /**
127     * Unix time at which the memoized success above stops being used
128     *
129     * @var int
130     */
131    private static $site_features_success_expires = 0;
132
133    /**
134     * Whether this module is a Jetpack feature
135     *
136     * @var boolean
137     */
138    public static $is_feature = false;
139
140    /**
141     * Whether this product requires a site connection
142     *
143     * @var string
144     */
145    public static $requires_site_connection = true;
146
147    /**
148     * Whether this product requires a user connection
149     *
150     * @var string
151     */
152    public static $requires_user_connection = true;
153
154    /**
155     * Whether this product has a standalone plugin
156     *
157     * @var bool
158     */
159    public static $has_standalone_plugin = false;
160
161    /**
162     * Whether this product has a free offering
163     *
164     * @var bool
165     */
166    public static $has_free_offering = false;
167
168    /**
169     * Whether the product requires a plan to run
170     * The plan could be paid or free
171     *
172     * @var bool
173     */
174    public static $requires_plan = false;
175
176    /**
177     * The feature slug that identifies the paid plan
178     *
179     * @var string
180     */
181    public static $feature_identifying_paid_plan = '';
182
183    /**
184     * Get the plugin slug
185     *
186     * @return ?string
187     */
188    public static function get_plugin_slug() {
189        return static::$plugin_slug;
190    }
191
192    /**
193     * Get the plugin filename
194     *
195     * @return ?string
196     */
197    public static function get_plugin_filename() {
198        return static::$plugin_filename;
199    }
200
201    /**
202     * This method will be called in the class initializer to register the product's endpoints
203     *
204     * @return void
205     */
206    public static function register_endpoints(): void {
207        // This method should be implemented in the child class.
208    }
209    /**
210     * Get data about the AI Assistant feature
211     *
212     * @return array
213     */
214    public static function get_ai_assistant_feature() {
215        // This method should be optionally set in the child class.
216        return array();
217    }
218
219    /**
220     * Get the WPCOM free product slug
221     *
222     * @return ?string
223     */
224    public static function get_wpcom_free_product_slug() {
225        return null;
226    }
227
228    /**
229     * Get the active installed copy, falling back to the first installed filename.
230     *
231     * @param string $plugin Which plugin to check. jetpack for the jetpack plugin or product for the product specific plugin.
232     *
233     * @return ?string
234     */
235    public static function get_installed_plugin_filename( $plugin = 'product' ) {
236        $all_plugins = Plugins_Installer::get_plugins();
237        $filename    = self::JETPACK_PLUGIN_SLUG === $plugin ? self::JETPACK_PLUGIN_FILENAME : static::get_plugin_filename();
238        if ( ! is_array( $filename ) ) {
239            $filename = array( $filename );
240        }
241        $first_installed = null;
242        // Products without a standalone plugin don't declare a filename, so drop the empty values.
243        foreach ( array_filter( $filename ) as $name ) {
244            if ( ! isset( $all_plugins[ $name ] ) ) {
245                continue;
246            }
247            if ( $all_plugins[ $name ]['active'] ) {
248                return $name;
249            }
250            if ( null === $first_installed ) {
251                $first_installed = $name;
252            }
253        }
254        return $first_installed;
255    }
256
257    /**
258     * Get the Static Product Info
259     *
260     * @throws \Exception If required attribute is not declared in the child class.
261     * @return array
262     */
263    public static function get_info() {
264        if ( static::$slug === null ) {
265            throw new \Exception( 'Product classes must declare the $slug attribute.' );
266        }
267        return array(
268            'slug'                            => static::$slug,
269            'plugin_slug'                     => static::get_plugin_slug(),
270            'name'                            => static::get_name(),
271            'title'                           => static::get_title(),
272            'category'                        => static::$category,
273            /* Maintain legacy compatibility with the old product info structure. See: #42271 */
274            'description'                     => static::get_description(),
275            'long_description'                => static::get_long_description(),
276            'tiers'                           => static::get_tiers(),
277            'features'                        => static::get_features(),
278            /* End of legacy compatibility fields. */
279            'disclaimers'                     => static::get_disclaimers(),
280            'is_bundle'                       => static::is_bundle_product(),
281            'is_plugin_active'                => static::is_plugin_active(),
282            'is_upgradable_by_bundle'         => static::is_upgradable_by_bundle(),
283            'is_feature'                      => static::$is_feature,
284            'supported_products'              => static::get_supported_products(),
285            'wpcom_product_slug'              => static::get_wpcom_product_slug(),
286            'requires_user_connection'        => static::$requires_user_connection,
287            'feature_identifying_paid_plan'   => static::$feature_identifying_paid_plan,
288            'has_free_offering'               => static::$has_free_offering,
289            'manage_url'                      => static::get_manage_url(),
290            // Whether to wait for `host_purchase_url`, which costs lookups and so comes with get_wpcom_info().
291            'host_may_sell'                   => Main_Features::may_host_sell_product( static::$slug ),
292            'post_activation_url'             => static::get_post_activation_url(),
293            'post_activation_urls_by_feature' => static::get_manage_urls_by_feature(),
294            'standalone_plugin_info'          => static::get_standalone_info(),
295            'class'                           => static::class,
296            'post_checkout_url'               => static::get_post_checkout_url(),
297            'post_checkout_urls_by_feature'   => static::get_post_checkout_urls_by_feature(),
298            'related_plan_slugs'              => static::get_related_plan_slugs(),
299        );
300    }
301
302    /**
303     * Get the related plan slugs including Free and Paid ones.
304     *
305     * @return array
306     */
307    public static function get_related_plan_slugs() {
308        $slugs = array_merge(
309            static::get_paid_bundles_that_include_product(),
310            static::get_paid_plan_product_slugs()
311        );
312
313        $free_product_slug = static::get_wpcom_free_product_slug();
314
315        if ( $free_product_slug ) {
316            $slugs[] = $free_product_slug;
317        }
318
319        return $slugs;
320    }
321
322    /**
323     * Get the Product Info that requires http requests to get
324     *
325     * @throws \Exception If required attribute is not declared in the child class.
326     * @return array
327     */
328    public static function get_wpcom_info() {
329        if ( static::$slug === null ) {
330            throw new \Exception( 'Product classes must declare the $slug attribute.' );
331        }
332
333        // Held for this call only: get_purchase_url() wants the same answer, and each ask costs ownership lookups.
334        $host_purchase_url                         = static::get_host_purchase_url();
335        $purchase_url                              = null;
336        self::$host_purchase_urls[ static::$slug ] = array( $host_purchase_url );
337        try {
338            $purchase_url = static::get_purchase_url();
339        } finally {
340            unset( self::$host_purchase_urls[ static::$slug ] );
341        }
342
343        $product_data = array(
344            'status'                        => static::get_status(),
345            'is_activated'                  => static::is_activated(),
346            'pricing_for_ui'                => static::get_pricing_for_ui(),
347            'is_upgradable'                 => static::is_upgradable(),
348            'description'                   => static::get_description(),
349            'tiers'                         => static::get_tiers(),
350            'features'                      => static::get_features(),
351            'long_description'              => static::get_long_description(),
352            'has_any_plan_for_product'      => static::has_any_plan_for_product(),
353            'has_free_plan_for_product'     => static::has_free_plan_for_product(),
354            'has_paid_plan_for_product'     => static::has_paid_plan_for_product(),
355            'purchase_url'                  => $purchase_url,
356            'host_purchase_url'             => $host_purchase_url,
357            'manage_paid_plan_purchase_url' => static::get_manage_paid_plan_purchase_url(),
358            'renew_paid_plan_purchase_url'  => static::get_renew_paid_plan_purchase_url(),
359            'does_module_need_attention'    => static::does_module_need_attention(),
360        );
361
362        if ( static::$slug === 'jetpack-ai' ) {
363            $product_data['ai-assistant-feature'] = static::get_ai_assistant_feature();
364        }
365        if ( in_array( static::$slug, array( 'security', 'growth' ), true ) ) {
366            $product_data['purchase_replacement'] = Products::get_bundle_offer( static::$slug );
367        }
368
369        return $product_data;
370    }
371
372    /**
373     * Collect the site's active features
374     *
375     * @return WP_Error|array
376     */
377    public static function get_site_features_from_wpcom() {
378        // Read the cache first, so a memoized failure can never outrank a warm lookup.
379        $stored_features = get_transient( self::MY_JETPACK_SITE_FEATURES_TRANSIENT_KEY );
380        if ( $stored_features !== false ) {
381            return $stored_features;
382        }
383
384        /*
385         * Checked after the transient so it can never outrank a warm cache, but kept so a
386         * dashboard render still makes a single WPCOM request when the transient write is dropped.
387         */
388        if ( self::$site_features_success !== null && time() < self::$site_features_success_expires ) {
389            return self::$site_features_success;
390        }
391
392        if ( self::$site_features_failure !== null && time() < self::$site_features_failure_expires ) {
393            return self::$site_features_failure;
394        }
395
396        $site_id  = Jetpack_Options::get_option( 'id' );
397        $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d/features', $site_id ), '1.1' );
398
399        if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
400            self::$site_features_failure         = new WP_Error( 'site_features_fetch_failed' );
401            self::$site_features_failure_expires = time() + self::MY_JETPACK_SITE_FEATURES_CACHE_DURATION;
402            return self::$site_features_failure;
403        }
404
405        $body           = wp_remote_retrieve_body( $response );
406        $feature_return = json_decode( $body );
407
408        $features = array(
409            'active'    => $feature_return->active,
410            'available' => $feature_return->available,
411        );
412
413        // set a short transient to help with multiple lookups on the same page load.
414        set_transient( self::MY_JETPACK_SITE_FEATURES_TRANSIENT_KEY, $features, self::MY_JETPACK_SITE_FEATURES_CACHE_DURATION );
415
416        self::$site_features_success         = $features;
417        self::$site_features_success_expires = time() + self::MY_JETPACK_SITE_FEATURES_CACHE_DURATION;
418
419        return $features;
420    }
421
422    /**
423     * Forget the cached site features â€” both in-process memos and the transient â€” so the next
424     * call asks WPCOM again.
425     *
426     * @return void
427     */
428    public static function reset_site_features_cache() {
429        self::$site_features_failure         = null;
430        self::$site_features_failure_expires = 0;
431        self::$site_features_success         = null;
432        self::$site_features_success_expires = 0;
433        delete_transient( self::MY_JETPACK_SITE_FEATURES_TRANSIENT_KEY );
434    }
435
436    /**
437     * Check to see if the site has a feature
438     * This will check the features provided by the site plans and products (including free ones)
439     *
440     * @param string $feature - the feature to check for.
441     * @return bool
442     */
443    public static function does_site_have_feature( $feature ) {
444        if ( ! $feature ) {
445            return false;
446        }
447
448        // Simple runs the API call in-process, which 404s for the v1.1 features route, so ask WordPress.com's own check.
449        if ( ( new Host() )->is_wpcom_simple() && function_exists( 'wpcom_site_has_feature' ) ) {
450            return \wpcom_site_has_feature( $feature );
451        }
452
453        $features = self::get_site_features_from_wpcom();
454        if ( is_wp_error( $features ) ) {
455            return false;
456        }
457
458        return in_array( $feature, $features['active'], true );
459    }
460
461    /**
462     * Get the product name
463     *
464     * @return string
465     */
466    abstract public static function get_name();
467
468    /**
469     * Get the product title
470     *
471     * @return string
472     */
473    abstract public static function get_title();
474
475    /**
476     * Get the internationalized product description
477     *
478     * @return string
479     */
480    abstract public static function get_description();
481
482    /**
483     * Get the internationalized product long description
484     *
485     * @return string
486     */
487    abstract public static function get_long_description();
488
489    /**
490     * Get the tiers for the product
491     *
492     * @return boolean|string[] The slugs of the tiers (i.e. [ "free", "basic", "advanced" ]), or False if the product has no tiers.
493     */
494    public static function get_tiers() {
495        return array();
496    }
497
498    /**
499     * Get the internationalized features list
500     *
501     * @return array
502     */
503    abstract public static function get_features();
504
505    /**
506     * Get the internationalized comparison of features grouped by each tier
507     *
508     * @deprecated 6.10.0
509     *
510     * @return array
511     */
512    public static function get_features_by_tier() {
513        _deprecated_function( __METHOD__, 'jetpack-my-jetpack-6.10.0' );
514
515        return array();
516    }
517
518    /**
519     * Get the product pricing
520     *
521     * @return array
522     */
523    abstract public static function get_pricing_for_ui();
524
525    /**
526     * Prepare supported billing terms, requiring confirmed availability for Pro.
527     *
528     * @since 6.12.0
529     * @param string[] $product_slugs Store product slugs, preferred term first.
530     * @return array Pricing details and term choices.
531     */
532    protected static function get_bundle_pricing( $product_slugs ) {
533        $terms = array();
534        foreach ( $product_slugs as $slug ) {
535            $product           = Wpcom_Products::get_product( $slug );
536            $valid_product     = is_object( $product ) && isset( $product->cost ) && isset( $product->currency_code ) && isset( $product->product_term ) && is_numeric( $product->cost ) && $product->cost >= 0;
537            $term              = array_merge(
538                array(
539                    'available'          => false,
540                    'wpcom_product_slug' => $slug,
541                ),
542                $valid_product ? Wpcom_Products::get_product_pricing( $slug ) : array()
543            );
544            $expected_term     = str_ends_with( $slug, '_monthly' ) ? 'month' : ( str_ends_with( $slug, '_bi_yearly' ) ? 'two years' : 'year' );
545            $on_sale           = str_starts_with( $slug, 'jetpack_pro_' ) ? true === ( $product->available ?? false ) : false !== ( $product->available ?? null );
546            $term['available'] = $valid_product && $on_sale && ( $term['product_term'] ?? '' ) === $expected_term;
547            $terms[]           = $term;
548        }
549        $available = array_values( array_filter( $terms, fn( $term ) => true === $term['available'] ) );
550        return array_merge( $available[0] ?? $terms[0], array( 'terms' => $terms ) );
551    }
552
553    /**
554     * Get the URL where the user can purchase the product iff it doesn't have an interstitial page in My Jetpack.
555     *
556     * @since 6.19.0 Returns the host's own address when it sells the product's feature.
557     *
558     * @return ?string
559     */
560    public static function get_purchase_url() {
561        // Most Jetpack products sell through an interstitial page within My Jetpack, so only a host names an address.
562        return static::get_host_purchase_url();
563    }
564
565    /**
566     * Get the URL where the site's host sells the product, in place of My Jetpack's interstitial page.
567     *
568     * @since 6.19.0
569     *
570     * @return ?string Null when no host sells it or the site already has it; '' when the host sells nothing here.
571     */
572    public static function get_host_purchase_url() {
573        if ( isset( self::$host_purchase_urls[ static::$slug ] ) ) {
574            return self::$host_purchase_urls[ static::$slug ][0];
575        }
576
577        return Main_Features::get_host_purchase_url( static::$slug );
578    }
579
580    /**
581     * Get the URL where the user manages the product
582     *
583     * @return ?string
584     */
585    abstract public static function get_manage_url();
586
587    /**
588     * Get the URL where the user manages the product for each product feature
589     *
590     * @return ?array
591     */
592    public static function get_manage_urls_by_feature() {
593        return null;
594    }
595
596    /**
597     * Get the URL the user is taken after activating the product
598     *
599     * @return ?string
600     */
601    public static function get_post_activation_url() {
602        return static::get_manage_url();
603    }
604
605    /**
606     * Get the URL the user is taken after purchasing the product through the checkout
607     *
608     * @return ?string
609     */
610    public static function get_post_checkout_url() {
611        return null;
612    }
613
614    /**
615     * Get the URL the user is taken after purchasing the product through the checkout for each product feature
616     *
617     * @return ?array
618     */
619    public static function get_post_checkout_urls_by_feature() {
620        return null;
621    }
622
623    /**
624     * Get the WPCOM product slug used to make the purchase
625     *
626     * @return ?string
627     */
628    public static function get_wpcom_product_slug() {
629        return null;
630    }
631
632    /**
633     * Get the disclaimers corresponding to a feature
634     *
635     * @return ?array
636     */
637    public static function get_disclaimers() {
638        return array();
639    }
640
641    /**
642     * Get the standalone plugin related info
643     *
644     * @return array
645     */
646    public static function get_standalone_info() {
647        $is_standalone_installed = static::$has_standalone_plugin && self::is_plugin_installed();
648        $is_standalone_active    = static::$has_standalone_plugin && self::is_plugin_active();
649
650        return array(
651            'has_standalone_plugin'   => static::$has_standalone_plugin,
652            'is_standalone_installed' => $is_standalone_installed,
653            'is_standalone_active'    => $is_standalone_active,
654        );
655    }
656
657    /**
658     * Checks whether the site has a paid plan for the product.
659     *
660     * This function relies on the product's `$feature_identifying_paid_plan` and `get_paid_plan_product_slugs()` function.
661     * If the product does not define a `$feature_identifying_paid_plan`, be sure the product includes functions for both
662     * `get_paid_plan_product_slugs()` and `get_paid_bundles_that_include_product()` which return all the product slugs and
663     * bundle slugs that include the product, respectively.
664     *
665     * @return boolean
666     */
667    public static function has_paid_plan_for_product() {
668        // First check site features (if there's a feature that identifies the paid plan)
669        if ( static::$feature_identifying_paid_plan ) {
670            if ( static::does_site_have_feature( static::$feature_identifying_paid_plan ) ) {
671                return true;
672            }
673        }
674        // Otherwise check site purchases
675        $plans_with_product = array_merge(
676            static::get_paid_bundles_that_include_product(),
677            static::get_paid_plan_product_slugs()
678        );
679
680        $purchases_data = Wpcom_Products::get_site_current_purchases();
681        if ( is_wp_error( $purchases_data ) ) {
682            return false;
683        }
684        if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
685            foreach ( $purchases_data as $purchase ) {
686                foreach ( $plans_with_product as $plan ) {
687                    if ( strpos( $purchase->product_slug, $plan ) !== false ) {
688                        return true;
689                    }
690                }
691            }
692        }
693
694        return false;
695    }
696
697    /**
698     * Checks whether the site has a free plan for the product
699     * Note, this should not return true if a product does not have a WPCOM plan (ex: search free, Akismet Free, stats free)
700     *
701     * @return false
702     */
703    public static function has_free_plan_for_product() {
704        return false;
705    }
706
707    /**
708     * Checks whether the site has any WPCOM plan for a product (paid or free)
709     *
710     * @return bool
711     */
712    public static function has_any_plan_for_product() {
713        return static::has_paid_plan_for_product() || static::has_free_plan_for_product();
714    }
715
716    /**
717     * Get the product-slugs of the paid plans for this product.
718     * (Do not include bundle plans, unless it's a bundle plan itself).
719     *
720     * @return array
721     */
722    public static function get_paid_plan_product_slugs() {
723        return array();
724    }
725
726    /**
727     * Get the product-slugs of the paid bundles/plans that this product/module is included in.
728     *
729     * This function relies on the product's `$feature_identifying_paid_plan`
730     * If the product does not define a `$feature_identifying_paid_plan`, be sure to include this
731     * function in the product's class and have it return all the paid bundle slugs that include
732     * the product.
733     *
734     * @return array
735     */
736    public static function get_paid_bundles_that_include_product() {
737        if ( static::is_bundle_product() ) {
738            return array();
739        }
740        $features = static::get_site_features_from_wpcom();
741        if ( is_wp_error( $features ) ) {
742            return array();
743        }
744        $idendifying_feature = static::$feature_identifying_paid_plan;
745        if ( empty( $features['available'] ) ) {
746            return array();
747        }
748        $paid_bundles   = $features['available']->$idendifying_feature ?? array();
749        $current_bundle = Wpcom_Products::get_site_current_plan( true );
750
751        if ( in_array( static::$feature_identifying_paid_plan, $current_bundle['features']['active'], true ) ) {
752            $paid_bundles[] = $current_bundle['product_slug'];
753        }
754
755        return $paid_bundles;
756    }
757
758    /**
759     * Gets the paid plan's purchase/subsciption info, or null if no paid plan purchases.
760     *
761     * @return object|null
762     */
763    public static function get_paid_plan_purchase_for_product() {
764        $paid_plans = array_merge(
765            static::get_paid_plan_product_slugs(),
766            static::get_paid_bundles_that_include_product()
767        );
768
769        $purchases_data = Wpcom_Products::get_site_current_purchases();
770        if ( is_wp_error( $purchases_data ) ) {
771            return null;
772        }
773
774        if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
775            foreach ( $purchases_data as $purchase ) {
776                foreach ( $paid_plans as $plan ) {
777                    if ( strpos( $purchase->product_slug, $plan ) !== false ) {
778                        return $purchase;
779                    }
780                }
781            }
782        }
783
784        return null;
785    }
786
787    /**
788     * Gets the paid plan's expiry date.
789     *
790     * @return string
791     */
792    public static function get_paid_plan_expiration_date() {
793        $purchase = static::get_paid_plan_purchase_for_product();
794        if ( ! $purchase ) {
795            return 'paid-plan-does-not-exist';
796        }
797
798        return $purchase->expiry_date;
799    }
800
801    /**
802     * Gets the paid plan's expiry status.
803     *
804     * @return string
805     */
806    public static function get_paid_plan_expiration_status() {
807        $purchase = static::get_paid_plan_purchase_for_product();
808        if ( ! $purchase ) {
809            return 'paid-plan-does-not-exist';
810        }
811
812        return $purchase->expiry_status;
813    }
814
815    /**
816     * Checks if the paid plan is expired or not.
817     *
818     * @param bool $not_expired_after_cutoff - whether to not return the plan as expired if the plan has been expired for some duration of time.
819     * @return bool
820     */
821    public static function is_paid_plan_expired( $not_expired_after_cutoff = false ) {
822        $expiry_status = static::get_paid_plan_expiration_status();
823        $expiry_date   = static::get_paid_plan_expiration_date();
824        $expiry_cutoff = strtotime( $expiry_date . ' ' . self::EXPIRATION_CUTOFF_TIME );
825
826        return $not_expired_after_cutoff
827            ? $expiry_status === Products::STATUS_EXPIRED && strtotime( 'now' ) < $expiry_cutoff
828            : $expiry_status === Products::STATUS_EXPIRED;
829    }
830
831    /**
832     * Checks if the paid plan is expiring soon or not.
833     *
834     * @return bool
835     */
836    public static function is_paid_plan_expiring() {
837        $expiry_status = static::get_paid_plan_expiration_status();
838
839        return $expiry_status === Products::STATUS_EXPIRING_SOON;
840    }
841
842    /**
843     * Gets the url to manage the paid plan's purchased subscription (for plan renewal, canceling, removal, etc).
844     *
845     * @return string|null The url to the purchase management page.
846     */
847    public static function get_manage_paid_plan_purchase_url() {
848        $purchase    = static::get_paid_plan_purchase_for_product();
849        $site_suffix = ( new Status() )->get_site_suffix();
850
851        if ( $purchase && $site_suffix ) {
852            return 'https://wordpress.com/me/purchases/' . $site_suffix . '/' . $purchase->ID;
853        }
854
855        return null;
856    }
857
858    /**
859     * Gets the url to renew the paid plan's purchased subscription.
860     *
861     * @return string|null The url to the checkout renewal page.
862     */
863    public static function get_renew_paid_plan_purchase_url() {
864        $purchase    = static::get_paid_plan_purchase_for_product();
865        $site_suffix = ( new Status() )->get_site_suffix();
866
867        if ( $purchase && $site_suffix ) {
868            return 'https://wordpress.com/checkout/' . $purchase->product_slug . '/renew/' . $purchase->ID . '/' . $site_suffix;
869        }
870
871        return null;
872    }
873
874    /**
875     * Checks whether the product supports trial or not
876     *
877     * Returns true if it supports. Return false otherwise.
878     *
879     * Free products will always return false.
880     *
881     * @return boolean
882     */
883    public static function has_trial_support() {
884        return false;
885    }
886
887    /**
888     * Checks whether the product can be upgraded to a different product.
889     *
890     * @return boolean
891     */
892    public static function is_upgradable() {
893        return ! static::has_paid_plan_for_product() && ! static::is_bundle_product();
894    }
895
896    /**
897     * Checks whether product is a bundle.
898     *
899     * @return boolean True if product is a bundle. Otherwise, False.
900     */
901    public static function is_bundle_product() {
902        return false;
903    }
904
905    /**
906     * Check whether the product is upgradable
907     * by a product bundle.
908     *
909     * @return boolean|array Bundles list or False if not upgradable by a bundle.
910     */
911    public static function is_upgradable_by_bundle() {
912        return false;
913    }
914
915    /**
916     * In case it's a bundle product,
917     * return all the products it contains.
918     * Empty array by default.
919     *
920     * @return array Product slugs
921     */
922    public static function get_supported_products() {
923        return array();
924    }
925
926    /**
927     * Determine if the product is owned or not
928     * An owned product is defined as a product that is any of the following
929     * - Active
930     * - Has historically been active
931     * - The user has a plan that includes the product
932     * - The user has the standalone plugin for the product installed
933     *
934     * @return boolean
935     */
936    public static function is_owned() {
937        $historically_active_modules = Jetpack_Options::get_option( 'historically_active_modules', array() );
938        $standalone_info             = static::get_standalone_info();
939        if ( ( static::is_active() && Jetpack_Options::get_option( 'id' ) ) ||
940            $standalone_info['is_standalone_installed'] ||
941            in_array( static::$slug, $historically_active_modules, true ) ||
942            static::has_any_plan_for_product()
943        ) {
944            return true;
945        }
946
947        return false;
948    }
949
950    /**
951     * Undocumented function
952     *
953     * @return string
954     */
955    public static function get_status() {
956        if ( ! static::is_plugin_installed() ) {
957            $status = Products::STATUS_PLUGIN_ABSENT;
958            if ( static::has_paid_plan_for_product() ) {
959                $status = Products::STATUS_PLUGIN_ABSENT_WITH_PLAN;
960            }
961        } elseif ( static::is_active() ) {
962            $status = Products::STATUS_ACTIVE;
963            // We only consider missing site & user connection an error when the Product is active.
964            if ( static::$requires_site_connection && ! ( new Connection_Manager() )->is_connected() ) {
965                // Site has never been connected before
966                if ( ! Jetpack_Options::get_option( 'id' ) && ! static::is_owned() ) {
967                    $status = Products::STATUS_NEEDS_FIRST_SITE_CONNECTION;
968                } else {
969                    $status = Products::STATUS_SITE_CONNECTION_ERROR;
970                }
971            } elseif ( static::$requires_user_connection && ! ( new Connection_Manager() )->has_connected_owner() ) {
972                $status = Products::STATUS_USER_CONNECTION_ERROR;
973            } elseif ( static::has_paid_plan_for_product() ) {
974                $needs_attention = static::does_module_need_attention();
975                if ( ! empty( $needs_attention ) && is_array( $needs_attention ) ) {
976                    $status = Products::STATUS_NEEDS_ATTENTION__WARNING;
977                    if ( isset( $needs_attention['type'] ) && 'error' === $needs_attention['type'] ) {
978                        $status = Products::STATUS_NEEDS_ATTENTION__ERROR;
979                    }
980                }
981                if ( static::is_paid_plan_expired() ) {
982                    $status = Products::STATUS_EXPIRED;
983                } elseif ( static::is_paid_plan_expiring() ) {
984                    $status = Products::STATUS_EXPIRING_SOON;
985                }
986            } elseif ( static::is_upgradable() ) {
987                $status = Products::STATUS_CAN_UPGRADE;
988            }
989            // Check specifically for inactive modules, which will prevent a product from being active
990            // Bundles have no module of their own, so they fall through to the plan checks below.
991        } elseif ( static::get_module_name() && ! static::is_bundle_product() && ! static::is_module_active() ) {
992            $status = Products::STATUS_MODULE_DISABLED;
993            // If there is not a plan associated with the disabled module, encourage a plan first
994            // Getting a plan set up should help resolve any connection issues
995            // However if the standalone plugin for this product is active, then we will defer to showing errors that prevent the module from being active
996            // This is because if a standalone plugin is installed, we expect the product to not show as "inactive" on My Jetpack
997            if ( ! static::has_any_plan_for_product() && ( static::$requires_plan || ( static::$has_standalone_plugin && ! self::is_plugin_active() ) ) ) {
998                $status = static::is_owned() && static::$has_free_offering && ! static::$requires_plan ? Products::STATUS_NEEDS_ACTIVATION : Products::STATUS_NEEDS_PLAN;
999            } elseif ( static::$requires_site_connection && ! ( new Connection_Manager() )->is_connected() ) {
1000                // Site has never been connected before and product is not owned
1001                if ( ! Jetpack_Options::get_option( 'id' ) && ! static::is_owned() ) {
1002                    $status = Products::STATUS_NEEDS_FIRST_SITE_CONNECTION;
1003                } else {
1004                    $status = Products::STATUS_SITE_CONNECTION_ERROR;
1005                }
1006            } elseif ( static::$requires_user_connection && ! ( new Connection_Manager() )->has_connected_owner() ) {
1007                $status = Products::STATUS_USER_CONNECTION_ERROR;
1008            }
1009        } elseif ( ! static::has_any_plan_for_product() ) {
1010            $status = static::is_owned() && static::$has_free_offering && ! static::$requires_plan ? Products::STATUS_NEEDS_ACTIVATION : Products::STATUS_NEEDS_PLAN;
1011        } else {
1012            $status = Products::STATUS_INACTIVE;
1013        }
1014        return $status;
1015    }
1016
1017    /**
1018     * Checks whether the Product is active
1019     *
1020     * @return boolean
1021     */
1022    public static function is_active() {
1023        return static::is_plugin_active() && ( static::has_any_plan_for_product() || ( ! static::$requires_plan && static::$has_free_offering ) );
1024    }
1025
1026    /**
1027     * Whether something other than its switch keeps the product off, such as a host or a filter.
1028     *
1029     * Turning its module or plugin on can't bring it back, so nothing should offer to.
1030     *
1031     * @since 6.19.0
1032     *
1033     * @return bool
1034     */
1035    public static function is_held_off() {
1036        return false;
1037    }
1038
1039    /**
1040     * Checks whether the site has switched the product on, whether or not it has a plan for it.
1041     *
1042     * Unlike is_active(), this never asks WordPress.com, so it is safe on every admin page load.
1043     * An override must keep it that way.
1044     *
1045     * @return boolean
1046     */
1047    public static function is_activated() {
1048        return static::is_plugin_active();
1049    }
1050
1051    /**
1052     * Checks whether the plugin is installed
1053     *
1054     * @return boolean
1055     */
1056    public static function is_plugin_installed() {
1057        return (bool) static::get_installed_plugin_filename();
1058    }
1059
1060    /**
1061     * Checks whether the plugin is active
1062     *
1063     * @return boolean
1064     */
1065    public static function is_plugin_active() {
1066        return Plugins_Installer::is_plugin_active( static::get_installed_plugin_filename() );
1067    }
1068
1069    /**
1070     * Checks whether the Jetpack plugin is installed
1071     *
1072     * @return boolean
1073     */
1074    public static function is_jetpack_plugin_installed() {
1075        return (bool) static::get_installed_plugin_filename( 'jetpack' );
1076    }
1077
1078    /**
1079     * Checks whether the Jetpack plugin is active
1080     *
1081     * @return boolean
1082     */
1083    public static function is_jetpack_plugin_active() {
1084        return Plugins_Installer::is_plugin_active( static::get_installed_plugin_filename( 'jetpack' ) );
1085    }
1086
1087    /**
1088     * Checks whether the Jetpack module is active only if a module_name is defined
1089     *
1090     * @return bool
1091     */
1092    public static function is_module_active() {
1093        $module_name = static::get_module_name();
1094        if ( $module_name ) {
1095            return ( new Modules() )->is_active( $module_name );
1096        }
1097        return true;
1098    }
1099
1100    /**
1101     * Get the Jetpack module that switches the product on, if any.
1102     *
1103     * @since 6.12.0
1104     *
1105     * @return ?string
1106     */
1107    public static function get_module_name() {
1108        return static::$module_name;
1109    }
1110
1111    /**
1112     * Activates the plugin
1113     *
1114     * @return null|WP_Error Null on success, WP_Error on invalid file.
1115     */
1116    public static function activate_plugin() {
1117        return activate_plugin( static::get_installed_plugin_filename() );
1118    }
1119
1120    /**
1121     * Perform the top level activation routines, which is installing and activating the required plugin
1122     *
1123     * @return bool|WP_Error
1124     */
1125    private static function do_activation() {
1126        if ( static::is_active() ) {
1127            return true;
1128        }
1129
1130        // Default to installing the standalone plugin for the product
1131        if ( ! self::is_plugin_installed() && static::should_use_standalone_plugin() ) {
1132            $installed = Plugins_Installer::install_plugin( static::get_plugin_slug() );
1133            if ( is_wp_error( $installed ) ) {
1134                return $installed;
1135            }
1136        }
1137
1138        if ( ! current_user_can( 'activate_plugins' ) ) {
1139            return new WP_Error( 'not_allowed', __( 'You are not allowed to activate plugins on this site.', 'jetpack-my-jetpack' ) );
1140        }
1141
1142        $result = static::activate_plugin();
1143        if ( is_wp_error( $result ) ) {
1144            return $result;
1145        }
1146
1147        return true;
1148    }
1149
1150    /**
1151     * Whether activating the product installs and activates its standalone plugin, rather than relying on the Jetpack plugin.
1152     *
1153     * @since 6.12.0
1154     *
1155     * @return bool
1156     */
1157    public static function should_use_standalone_plugin() {
1158        return true;
1159    }
1160
1161    /**
1162     * Activates the product by installing and activating its plugin
1163     *
1164     * @return boolean|WP_Error
1165     */
1166    final public static function activate() {
1167
1168        $result = self::do_activation();
1169
1170        $result = static::do_product_specific_activation( $result );
1171
1172        $product_slug = static::$slug;
1173
1174        /**
1175         * Fires after My Jetpack activates a product and filters the result
1176         * Use this filter to run additional routines for a product activation on stand-alone plugins
1177         *
1178         * @param bool|WP_Error $result The result of the previous steps of activation.
1179         */
1180        $result = apply_filters( "my_jetpack_{$product_slug}_activation", $result );
1181
1182        return $result;
1183    }
1184
1185    /**
1186     * Override this method to perform product specific activation routines.
1187     *
1188     * @param bool|WP_Error $current_result Is the result of the top level activation actions. You probably won't do anything if it is an WP_Error.
1189     * @return bool|WP_Error
1190     */
1191    public static function do_product_specific_activation( $current_result ) {
1192        return $current_result;
1193    }
1194
1195    /**
1196     * Deactivate the product
1197     *
1198     * @return boolean
1199     */
1200    public static function deactivate() {
1201        deactivate_plugins( static::get_installed_plugin_filename() );
1202        return true;
1203    }
1204
1205    /**
1206     * Returns filtered Jetpack plugin actions links.
1207     *
1208     * @param array $actions - Jetpack plugin action links.
1209     * @return array           Filtered Jetpack plugin actions links.
1210     */
1211    public static function get_plugin_actions_links( $actions ) {
1212        // My Jetpack action link.
1213        $my_jetpack_home_link = array(
1214            'jetpack-home' => sprintf(
1215                '<a href="%1$s" title="%3$s">%2$s</a>',
1216                admin_url( 'admin.php?page=my-jetpack' ),
1217                __( 'My Jetpack', 'jetpack-my-jetpack' ),
1218                __( 'My Jetpack dashboard', 'jetpack-my-jetpack' )
1219            ),
1220        );
1221
1222        // Otherwise, add it to the beginning of the array.
1223        return array_merge( $my_jetpack_home_link, $actions );
1224    }
1225
1226    /**
1227     * Filter the action links for the plugins specified.
1228     *
1229     * @param string|string[] $filenames The plugin filename(s) to filter the action links for.
1230     */
1231    private static function filter_action_links( $filenames ) {
1232        foreach ( $filenames as $filename ) {
1233            $hook     = 'plugin_action_links_' . $filename;
1234            $callback = array( static::class, 'get_plugin_actions_links' );
1235            if ( ! has_filter( $hook, $callback ) ) {
1236                add_filter( $hook, $callback, 20, 2 );
1237            }
1238        }
1239    }
1240
1241    /**
1242     * Extend the plugin action links.
1243     */
1244    public static function extend_plugin_action_links() {
1245        $filenames = static::get_plugin_filename();
1246        if ( ! is_array( $filenames ) ) {
1247            $filenames = array( $filenames );
1248        }
1249
1250        self::filter_action_links( $filenames );
1251    }
1252
1253    /**
1254     * Extend the Jetpack plugin action links.
1255     */
1256    public static function extend_core_plugin_action_links() {
1257        $filenames = self::JETPACK_PLUGIN_FILENAME;
1258
1259        self::filter_action_links( $filenames );
1260    }
1261
1262    /**
1263     * Install and activate the standalone plugin in the case it's missing.
1264     *
1265     * @return boolean|WP_Error
1266     */
1267    public static function install_and_activate_standalone() {
1268        /**
1269         * Check for the presence of the standalone plugin, ignoring Jetpack presence.
1270         *
1271         * If the standalone plugin is not installed and the user can install plugins, proceed with the installation.
1272         */
1273        if ( ! static::is_plugin_installed() ) {
1274            /**
1275             * Check for permissions
1276             */
1277            if ( ! current_user_can( 'install_plugins' ) ) {
1278                return new WP_Error( 'not_allowed', __( 'You are not allowed to install plugins on this site.', 'jetpack-my-jetpack' ) );
1279            }
1280
1281            /**
1282             * Install the plugin
1283             */
1284            $installed = Plugins_Installer::install_plugin( static::get_plugin_slug() );
1285            if ( is_wp_error( $installed ) ) {
1286                return $installed;
1287            }
1288        }
1289
1290        /**
1291         * Activate the installed plugin
1292         */
1293        $result = static::activate_plugin();
1294
1295        if ( is_wp_error( $result ) ) {
1296            return $result;
1297        }
1298
1299        return true;
1300    }
1301
1302    /**
1303     * Determines whether the module/plugin/product needs the users attention.
1304     * Typically due to some sort of error where user troubleshooting is needed.
1305     *
1306     * @return boolean
1307     */
1308    public static function does_module_need_attention() {
1309        return false;
1310    }
1311}