Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.04% covered (warning)
66.04%
35 / 53
80.00% covered (warning)
80.00%
12 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 1
Growth
66.67% covered (warning)
66.67%
34 / 51
80.00% covered (warning)
80.00%
12 / 15
54.00
0.00% covered (danger)
0.00%
0 / 1
 get_name
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_title
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 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%
8 / 8
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 / 10
0.00% covered (danger)
0.00%
0 / 1
30
 is_active
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 has_required_plan
40.00% covered (danger)
40.00%
4 / 10
0.00% covered (danger)
0.00%
0 / 1
21.82
 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
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_manage_url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Growth 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 Growth plan
20 */
21class Growth extends Module_Product {
22
23    /**
24     * The product slug
25     *
26     * @var string
27     */
28    public static $slug = 'growth';
29
30    /**
31     * The Jetpack module name
32     *
33     * @var string
34     */
35    public static $module_name = 'growth';
36
37    /**
38     * Get the product name
39     *
40     * @return string
41     */
42    public static function get_name() {
43        return 'Growth Bundle';
44    }
45
46    /**
47     * Get the product title
48     *
49     * @return string
50     */
51    public static function get_title() {
52        return 'Jetpack Growth';
53    }
54
55    /**
56     * Get the internationalized product description
57     *
58     * @return string
59     */
60    public static function get_description() {
61        return __( 'Grow and track your audience effortlessly.', '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 __( 'Essential tools to help you grow your audience, track visitor engagement, and turn leads into loyal customers and advocates.', 'jetpack-my-jetpack' );
71    }
72
73    /**
74     * Get the internationalized feature list
75     *
76     * @return array Growth features list
77     */
78    public static function get_features() {
79        return array(
80            _x( 'Jetpack Social', 'Growth Product Feature', 'jetpack-my-jetpack' ),
81            _x( 'Jetpack Stats (10K site views, upgradeable)', 'Growth Product Feature', 'jetpack-my-jetpack' ),
82            _x( 'Unlimited subscriber imports', 'Growth Product Feature', 'jetpack-my-jetpack' ),
83            _x( 'Earn more from your content', 'Growth Product Feature', 'jetpack-my-jetpack' ),
84            _x( 'Accept payments with PayPal', 'Growth Product Feature', 'jetpack-my-jetpack' ),
85            _x( 'Increase earnings with WordAds', 'Growth Product Feature', 'jetpack-my-jetpack' ),
86        );
87    }
88
89    /**
90     * Get the product pricing details
91     *
92     * @return array Pricing details
93     */
94    public static function get_pricing_for_ui() {
95        $product_slug = static::get_wpcom_product_slug();
96        return array_merge(
97            array(
98                'available'          => true,
99                'wpcom_product_slug' => $product_slug,
100            ),
101            Wpcom_Products::get_product_pricing( $product_slug )
102        );
103    }
104
105    /**
106     * Get the WPCOM product slug used to make the purchase
107     *
108     * @return string
109     */
110    public static function get_wpcom_product_slug() {
111        return 'jetpack_growth_yearly';
112    }
113
114    /**
115     * Checks whether the Jetpack module is active
116     *
117     * This is a bundle and not a product. We should not use this information for anything
118     *
119     * @return bool
120     */
121    public static function is_module_active() {
122        return false;
123    }
124
125    /**
126     * Activates the product by installing and activating its plugin
127     *
128     * @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.
129     * @return bool|\WP_Error
130     */
131    public static function do_product_specific_activation( $current_result ) {
132        $product_activation = parent::do_product_specific_activation( $current_result );
133
134        // 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.
135        if ( is_wp_error( $product_activation ) && 'module_activation_failed' === $product_activation->get_error_code() ) {
136            return $product_activation;
137        }
138
139        // At this point, Jetpack plugin is installed. Let's activate each individual product.
140        $activation = Social::activate();
141        if ( is_wp_error( $activation ) ) {
142            return $activation;
143        }
144
145        $activation = Stats::activate();
146        if ( is_wp_error( $activation ) ) {
147            return $activation;
148        }
149
150        return $activation;
151    }
152
153    /**
154     * Checks whether the Product is active
155     *
156     * Growth 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.
157     *
158     * @return bool
159     */
160    public static function is_active() {
161        return static::is_jetpack_plugin_active() && static::has_required_plan();
162    }
163
164    /**
165     * Checks whether the current plan (or purchase) of the site already supports the product
166     *
167     * @return bool
168     */
169    public static function has_required_plan() {
170        $purchases_data = Wpcom_Products::get_site_current_purchases();
171        if ( is_wp_error( $purchases_data ) ) {
172            return false;
173        }
174        if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
175            foreach ( $purchases_data as $purchase ) {
176                if (
177                    str_starts_with( $purchase->product_slug, 'jetpack_growth' ) ||
178                    str_starts_with( $purchase->product_slug, 'jetpack_complete' ) ||
179                    str_starts_with( $purchase->product_slug, 'jetpack_pro_' )
180                ) {
181                    return true;
182                }
183            }
184        }
185        return false;
186    }
187
188    /**
189     * Get the product-slugs of the paid plans for this product.
190     * (Do not include bundle plans, unless it's a bundle plan itself).
191     *
192     * @return array
193     */
194    public static function get_paid_plan_product_slugs() {
195        return array(
196            'jetpack_growth_yearly',
197            'jetpack_growth_monthly',
198            'jetpack_growth_bi_yearly',
199        );
200    }
201
202    /**
203     * Checks whether the product is a bundle
204     *
205     * @return bool
206     */
207    public static function is_bundle_product() {
208        return true;
209    }
210
211    /**
212     * Returns all products it contains.
213     *
214     * @return array Product slugs
215     */
216    public static function get_supported_products() {
217        return array( 'social', 'stats' );
218    }
219
220    /**
221     * Get the URL where the user manages the product
222     *
223     * @return string
224     */
225    public static function get_manage_url() {
226        return '';
227    }
228}