Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 15
CRAP
0.00% covered (danger)
0.00%
0 / 1
Starter
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 15
650
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
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_long_description
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_features
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 get_pricing_for_ui
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 get_wpcom_product_slug
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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
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
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 is_bundle_product
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_supported_products
0.00% covered (danger)
0.00%
0 / 1
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 * Starter 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 Starter plan
20 */
21class Starter extends Module_Product {
22
23    /**
24     * The product slug
25     *
26     * @var string
27     */
28    public static $slug = 'starter';
29
30    /**
31     * The Jetpack module name
32     *
33     * @var string
34     */
35    public static $module_name = 'starter';
36
37    /**
38     * Get the product name
39     *
40     * @return string
41     */
42    public static function get_name() {
43        return 'Starter';
44    }
45
46    /**
47     * Get the product title
48     *
49     * @return string
50     */
51    public static function get_title() {
52        return 'Jetpack Starter';
53    }
54
55    /**
56     * Get the internationalized product description
57     *
58     * @return string
59     */
60    public static function get_description() {
61        return __( 'Essential security tools: real-time backups and comment spam protection.', 'jetpack-my-jetpack' );
62    }
63
64    /**
65     * Get the internationalized product long description
66     *
67     * @return string
68     */
69    public static function get_long_description() {
70        return __( 'Essential security tools: real-time backups and comment spam protection.', 'jetpack-my-jetpack' );
71    }
72
73    /**
74     * Get the internationalized features list
75     *
76     * @return array Starter features list
77     */
78    public static function get_features() {
79        return array(
80            _x( 'Real-time cloud backups with 1GB storage', 'Starter Product Feature', 'jetpack-my-jetpack' ),
81            _x( 'One-click fixes for most threats', 'Starter Product Feature', 'jetpack-my-jetpack' ),
82            _x( 'Comment & form spam protection', 'Starter Product Feature', 'jetpack-my-jetpack' ),
83        );
84    }
85
86    /**
87     * Get the product princing details
88     *
89     * @return array Pricing details
90     */
91    public static function get_pricing_for_ui() {
92        return array_merge(
93            array(
94                'available'          => true,
95                'wpcom_product_slug' => static::get_wpcom_product_slug(),
96            ),
97            Wpcom_Products::get_product_pricing( static::get_wpcom_product_slug() )
98        );
99    }
100
101    /**
102     * Get the WPCOM product slug used to make the purchase
103     *
104     * @return ?string
105     */
106    public static function get_wpcom_product_slug() {
107        return 'jetpack_starter_yearly';
108    }
109
110    /**
111     * Checks whether the Jetpack module is active
112     *
113     * This is a bundle and not a product. We should not use this information for anything
114     *
115     * @return bool
116     */
117    public static function is_module_active() {
118        return false;
119    }
120
121    /**
122     * Activates the product by installing and activating its plugin
123     *
124     * @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.
125     * @return boolean|\WP_Error
126     */
127    public static function do_product_specific_activation( $current_result ) {
128
129        $product_activation = parent::do_product_specific_activation( $current_result );
130
131        if ( is_wp_error( $product_activation ) && 'module_activation_failed' === $product_activation->get_error_code() ) {
132            // 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.
133            $product_activation = true;
134        }
135
136        // At this point, Jetpack plugin is installed. Let's activate each individual product.
137        $activation = Anti_Spam::activate();
138        if ( is_wp_error( $activation ) ) {
139            return $activation;
140        }
141
142        $activation = Backup::activate();
143        if ( is_wp_error( $activation ) ) {
144            return $activation;
145        }
146
147        return $activation;
148    }
149
150    /**
151     * Checks whether the Product is active
152     *
153     * Jetpack Starter 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.
154     *
155     * @return boolean
156     */
157    public static function is_active() {
158        return static::is_jetpack_plugin_active() && static::has_required_plan();
159    }
160
161    /**
162     * Checks whether the current plan (or purchases) of the site already supports the product
163     *
164     * @return boolean
165     */
166    public static function has_required_plan() {
167        $purchases_data = Wpcom_Products::get_site_current_purchases();
168        if ( is_wp_error( $purchases_data ) ) {
169            return false;
170        }
171        if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
172            foreach ( $purchases_data as $purchase ) {
173                if ( str_starts_with( $purchase->product_slug, 'jetpack_starter' ) ) {
174                    return true;
175                }
176            }
177        }
178        return false;
179    }
180
181    /**
182     * Get the product-slugs of the paid plans for this product.
183     * (Do not include bundle plans, unless it's a bundle plan itself).
184     *
185     * @return array
186     */
187    public static function get_paid_plan_product_slugs() {
188        return array(
189            'jetpack_starter_yearly',
190            'jetpack_starter_monthly',
191        );
192    }
193
194    /**
195     * Checks whether product is a bundle.
196     *
197     * @return boolean True
198     */
199    public static function is_bundle_product() {
200        return true;
201    }
202
203    /**
204     * Return all the products it contains.
205     *
206     * @return Array Product slugs
207     */
208    public static function get_supported_products() {
209        return array( 'backup', 'anti-spam' );
210    }
211
212    /**
213     * Get the URL where the user manages the product
214     *
215     * @return ?string
216     */
217    public static function get_manage_url() {
218        return '';
219    }
220}