Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
35.23% covered (danger)
35.23%
31 / 88
46.67% covered (danger)
46.67%
7 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 1
Complete
34.88% covered (danger)
34.88%
30 / 86
46.67% covered (danger)
46.67%
7 / 15
314.73
0.00% covered (danger)
0.00%
0 / 1
 get_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_title
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_description
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_long_description
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_features
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 get_pricing_for_ui
100.00% covered (success)
100.00%
8 / 8
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
 is_module_active
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 do_product_specific_activation
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
156
 is_active
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 has_required_plan
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
42
 get_paid_plan_product_slugs
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 is_bundle_product
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_supported_products
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 get_manage_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Complete plan
4 *
5 * @package my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack\Products;
9
10use Automattic\Jetpack\My_Jetpack\Module_Product;
11use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
12use WP_Error;
13
14if ( ! defined( 'ABSPATH' ) ) {
15    exit( 0 );
16}
17
18/**
19 * Class responsible for handling the Complete plan
20 */
21class Complete extends Module_Product {
22
23    /**
24     * The product slug
25     *
26     * @var string
27     */
28    public static $slug = 'complete';
29
30    /**
31     * The Jetpack module name
32     *
33     * @var string
34     */
35    public static $module_name = 'complete';
36
37    /**
38     * Get the product name
39     *
40     * @return string
41     */
42    public static function get_name() {
43        return 'Complete Bundle';
44    }
45
46    /**
47     * Get the product title
48     *
49     * @return string
50     */
51    public static function get_title() {
52        return 'Jetpack Complete';
53    }
54
55    /**
56     * Get the internationalized product description
57     *
58     * @return string
59     */
60    public static function get_description() {
61        return __( 'The ultimate tool kit for best-in-class websites.', 'jetpack-my-jetpack' );
62    }
63
64    /**
65     * Get the internationalized product description
66     *
67     * @return string
68     */
69    public static function get_long_description() {
70        return __( 'Get the full Jetpack suite with real-time security tools, improved site performance, and tools to grow your business.', 'jetpack-my-jetpack' );
71    }
72
73    /**
74     * Get the internationalized features list
75     * Most of these are not translated as they are product names
76     *
77     * @return array Complete features list
78     */
79    public static function get_features() {
80        return array(
81            'VaultPress Backup',
82            'Scan',
83            'Akismet Anti-spam',
84            'VideoPress',
85            'Boost',
86            'Social',
87            'Search',
88            'AI Assistant',
89            _x( 'Stats (100K site views, upgradeable)', 'Complete Product Feature', 'jetpack-my-jetpack' ),
90            _x( 'CRM Entrepreneur', 'Complete Product Feature', 'jetpack-my-jetpack' ),
91            _x( 'Newsletter and monetization tools', 'Complete Product Feature', 'jetpack-my-jetpack' ),
92        );
93    }
94
95    /**
96     * Get the product pricing details
97     *
98     * @return array Pricing details
99     */
100    public static function get_pricing_for_ui() {
101        $product_slug = static::get_wpcom_product_slug();
102        return array_merge(
103            array(
104                'available'          => true,
105                'wpcom_product_slug' => $product_slug,
106            ),
107            Wpcom_Products::get_product_pricing( $product_slug )
108        );
109    }
110
111    /**
112     * Get the WPCOM product slug used to make the purchase
113     *
114     * @return string
115     */
116    public static function get_wpcom_product_slug() {
117        return 'jetpack_complete';
118    }
119
120    /**
121     * Checks whether the Jetpack module is active
122     *
123     * This is a bundle and not a product. We should not use this information for anything
124     *
125     * @return bool
126     */
127    public static function is_module_active() {
128        return false;
129    }
130
131    /**
132     * Activates the product by installing and activating its plugin
133     *
134     * @param WP_Error|bool $current_result Is the result of the top level activation actions. You probably won't do anything if it is an WP_Error.
135     * @return bool|\WP_Error
136     */
137    public static function do_product_specific_activation( $current_result ) {
138        $product_activation = parent::do_product_specific_activation( $current_result );
139
140        // A bundle is not a module. There's nothing in the plugin to be activated, so it's ok to fail to activate the module.
141        if ( is_wp_error( $product_activation ) && 'module_activation_failed' === $product_activation->get_error_code() ) {
142            return $product_activation;
143        }
144
145        // At this point, Jetpack plugin is installed. Let's activate each individual product.
146        $activation = Social::activate();
147        if ( is_wp_error( $activation ) ) {
148            return $activation;
149        }
150
151        $activation = Stats::activate();
152        if ( is_wp_error( $activation ) ) {
153            return $activation;
154        }
155
156        $activation = Anti_Spam::activate();
157        if ( is_wp_error( $activation ) ) {
158            return $activation;
159        }
160
161        $activation = Backup::activate();
162        if ( is_wp_error( $activation ) ) {
163            return $activation;
164        }
165
166        $activation = Scan::activate();
167        if ( is_wp_error( $activation ) ) {
168            return $activation;
169        }
170
171        $activation = Boost::activate();
172        if ( is_wp_error( $activation ) ) {
173            return $activation;
174        }
175
176        $activation = CRM::activate();
177        if ( is_wp_error( $activation ) ) {
178            return $activation;
179        }
180
181        $activation = Search::activate();
182        if ( is_wp_error( $activation ) ) {
183            return $activation;
184        }
185
186        $activation = VideoPress::activate();
187        if ( is_wp_error( $activation ) ) {
188            return $activation;
189        }
190
191        return $activation;
192    }
193
194    /**
195     * Checks whether the Product is active
196     *
197     * Security is a bundle and not a module. Activation takes place on WPCOM. So lets consider it active if jetpack is active and has the plan.
198     *
199     * @return boolean
200     */
201    public static function is_active() {
202        return static::is_jetpack_plugin_active() && static::has_required_plan();
203    }
204
205    /**
206     * Checks whether the current plan (or purchases) of the site already supports the product
207     *
208     * @return boolean
209     */
210    public static function has_required_plan() {
211        $purchases_data = Wpcom_Products::get_site_current_purchases();
212        if ( is_wp_error( $purchases_data ) ) {
213            return false;
214        }
215        if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
216            foreach ( $purchases_data as $purchase ) {
217                if ( str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ) {
218                    return true;
219                }
220            }
221        }
222        return false;
223    }
224
225    /**
226     * Get the product-slugs of the paid plans for this product.
227     * (Do not include bundle plans, unless it's a bundle plan itself).
228     *
229     * @return array
230     */
231    public static function get_paid_plan_product_slugs() {
232        return array(
233            'jetpack_complete',
234            'jetpack_complete_monthly',
235            'jetpack_complete_bi_yearly',
236        );
237    }
238
239    /**
240     * Checks whether product is a bundle.
241     *
242     * @return boolean True
243     */
244    public static function is_bundle_product() {
245        return true;
246    }
247
248    /**
249     * Return all the products it contains.
250     *
251     * @return array Product slugs
252     */
253    public static function get_supported_products() {
254        return array(
255            'anti-spam',
256            'backup',
257            'boost',
258            'crm',
259            'scan',
260            'search',
261            'social',
262            'stats',
263            'videopress',
264            'jetpack-ai',
265        );
266    }
267
268    /**
269     * Get the URL where the user manages the product
270     *
271     * @return ?string
272     */
273    public static function get_manage_url() {
274        return '';
275    }
276}