Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
26 / 52 |
|
46.67% |
7 / 15 |
CRAP | |
0.00% |
0 / 1 |
| Growth | |
50.00% |
25 / 50 |
|
46.67% |
7 / 15 |
110.50 | |
0.00% |
0 / 1 |
| get_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_title | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_description | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_long_description | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_features | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| get_pricing_for_ui | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| get_wpcom_product_slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| is_module_active | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| do_product_specific_activation | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| is_active | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| has_required_plan | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
56 | |||
| get_paid_plan_product_slugs | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| is_bundle_product | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_supported_products | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_manage_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Growth plan |
| 4 | * |
| 5 | * @package my-jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\My_Jetpack\Products; |
| 9 | |
| 10 | use Automattic\Jetpack\My_Jetpack\Module_Product; |
| 11 | use Automattic\Jetpack\My_Jetpack\Wpcom_Products; |
| 12 | use WP_Error; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class responsible for handling the Growth plan |
| 20 | */ |
| 21 | class 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 | ) { |
| 180 | return true; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Get the product-slugs of the paid plans for this product. |
| 189 | * (Do not include bundle plans, unless it's a bundle plan itself). |
| 190 | * |
| 191 | * @return array |
| 192 | */ |
| 193 | public static function get_paid_plan_product_slugs() { |
| 194 | return array( |
| 195 | 'jetpack_growth_yearly', |
| 196 | 'jetpack_growth_monthly', |
| 197 | 'jetpack_growth_bi_yearly', |
| 198 | ); |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Checks whether the product is a bundle |
| 203 | * |
| 204 | * @return bool |
| 205 | */ |
| 206 | public static function is_bundle_product() { |
| 207 | return true; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Returns all products it contains. |
| 212 | * |
| 213 | * @return array Product slugs |
| 214 | */ |
| 215 | public static function get_supported_products() { |
| 216 | return array( 'social', 'stats' ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get the URL where the user manages the product |
| 221 | * |
| 222 | * @return string |
| 223 | */ |
| 224 | public static function get_manage_url() { |
| 225 | return ''; |
| 226 | } |
| 227 | } |