Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
98.48% |
195 / 198 |
|
92.31% |
12 / 13 |
CRAP | |
0.00% |
0 / 1 |
| Boost | |
99.49% |
195 / 196 |
|
92.31% |
12 / 13 |
15 | |
0.00% |
0 / 1 |
| get_name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_title | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| get_tiers | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| get_features_by_tier | |
100.00% |
155 / 155 |
|
100.00% |
1 / 1 |
1 | |||
| get_post_checkout_url | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_pricing_for_ui | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| get_manage_url | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| do_product_specific_activation | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
3.07 | |||
| get_paid_plan_product_slugs | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| is_upgradable_by_bundle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Boost product |
| 4 | * |
| 5 | * @package my-jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\My_Jetpack\Products; |
| 9 | |
| 10 | use Automattic\Jetpack\My_Jetpack\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 Boost product |
| 20 | */ |
| 21 | class Boost extends Product { |
| 22 | |
| 23 | const FREE_TIER_SLUG = 'free'; |
| 24 | const UPGRADED_TIER_SLUG = 'upgraded'; |
| 25 | const UPGRADED_TIER_PRODUCT_SLUG = 'jetpack_boost_yearly'; |
| 26 | |
| 27 | /** |
| 28 | * The product slug |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | public static $slug = 'boost'; |
| 33 | |
| 34 | /** |
| 35 | * The filename (id) of the plugin associated with this product. |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | public static $plugin_filename = array( |
| 40 | 'jetpack-boost/jetpack-boost.php', |
| 41 | 'boost/jetpack-boost.php', |
| 42 | 'jetpack-boost-dev/jetpack-boost.php', |
| 43 | ); |
| 44 | /** |
| 45 | * The slug of the plugin associated with this product. |
| 46 | * |
| 47 | * @var string |
| 48 | */ |
| 49 | public static $plugin_slug = 'jetpack-boost'; |
| 50 | |
| 51 | /** |
| 52 | * The category of the product |
| 53 | * |
| 54 | * @var string |
| 55 | */ |
| 56 | public static $category = 'performance'; |
| 57 | |
| 58 | /** |
| 59 | * Defines whether or not to show a product interstitial as tiered pricing or not |
| 60 | * |
| 61 | * @var bool |
| 62 | */ |
| 63 | public static $is_tiered_pricing = true; |
| 64 | |
| 65 | /** |
| 66 | * Boost has a standalone plugin |
| 67 | * |
| 68 | * @var bool |
| 69 | */ |
| 70 | public static $has_standalone_plugin = true; |
| 71 | |
| 72 | /** |
| 73 | * Whether this product requires a user connection |
| 74 | * |
| 75 | * @var string |
| 76 | */ |
| 77 | public static $requires_user_connection = false; |
| 78 | |
| 79 | /** |
| 80 | * Whether this product has a free offering |
| 81 | * |
| 82 | * @var bool |
| 83 | */ |
| 84 | public static $has_free_offering = true; |
| 85 | |
| 86 | /** |
| 87 | * The feature slug that identifies the paid plan |
| 88 | * |
| 89 | * @var string |
| 90 | */ |
| 91 | public static $feature_identifying_paid_plan = 'cloud-critical-css'; |
| 92 | |
| 93 | /** |
| 94 | * Get the product name |
| 95 | * |
| 96 | * @return string |
| 97 | */ |
| 98 | public static function get_name() { |
| 99 | return 'Boost'; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get the product title |
| 104 | * |
| 105 | * @return string |
| 106 | */ |
| 107 | public static function get_title() { |
| 108 | return 'Jetpack Boost'; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get the internationalized product description |
| 113 | * |
| 114 | * @return string |
| 115 | */ |
| 116 | public static function get_description() { |
| 117 | return __( 'Improves your site speed and performance.', 'jetpack-my-jetpack' ); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Get the internationalized product long description |
| 122 | * |
| 123 | * @return string |
| 124 | */ |
| 125 | public static function get_long_description() { |
| 126 | return __( 'Fast sites get more page visits, more conversions, and better SEO rankings. Boost speeds up your site in seconds.', 'jetpack-my-jetpack' ); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get the internationalized features list |
| 131 | * |
| 132 | * @return array Boost features list |
| 133 | */ |
| 134 | public static function get_features() { |
| 135 | return array( |
| 136 | __( 'Check your site performance', 'jetpack-my-jetpack' ), |
| 137 | __( 'Enable improvements in one click', 'jetpack-my-jetpack' ), |
| 138 | __( 'Standalone free plugin for those focused on speed', 'jetpack-my-jetpack' ), |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Get the product's available tiers |
| 144 | * |
| 145 | * @return string[] Slugs of the available tiers |
| 146 | */ |
| 147 | public static function get_tiers() { |
| 148 | return array( |
| 149 | self::UPGRADED_TIER_SLUG, |
| 150 | self::FREE_TIER_SLUG, |
| 151 | ); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Get the internationalized comparison of free vs upgraded features |
| 156 | * |
| 157 | * @return array[] Protect features comparison |
| 158 | */ |
| 159 | public static function get_features_by_tier() { |
| 160 | return array( |
| 161 | array( |
| 162 | 'name' => __( 'Auto CSS Optimization', 'jetpack-my-jetpack' ), |
| 163 | 'info' => array( |
| 164 | 'content' => __( |
| 165 | 'Move important styling information to the start of the page, which helps pages display your content sooner, so your users don’t have to wait for the entire page to load. Commonly referred to as Critical CSS.', |
| 166 | 'jetpack-my-jetpack' |
| 167 | ), |
| 168 | ), |
| 169 | 'tiers' => array( |
| 170 | self::FREE_TIER_SLUG => array( |
| 171 | 'included' => false, |
| 172 | 'description' => __( 'Manual', 'jetpack-my-jetpack' ), |
| 173 | 'info' => array( |
| 174 | 'title' => __( 'Manual Critical CSS regeneration', 'jetpack-my-jetpack' ), |
| 175 | 'content' => __( |
| 176 | '<p>To enhance the speed of your site, with this plan you will need to optimize CSS by using the Manual Critical CSS generation feature whenever you:</p> |
| 177 | <ul> |
| 178 | <li>Make theme changes.</li> |
| 179 | <li>Write a new post/page.</li> |
| 180 | <li>Edit a post/page.</li> |
| 181 | <li>Activate, deactivate, or update plugins that impact your site layout or HTML structure.</li> |
| 182 | <li>Change settings of plugins that impact your site layout or HTML structure.</li> |
| 183 | <li>Upgrade your WordPress version if the new release includes core CSS changes.</li> |
| 184 | </ul>', |
| 185 | 'jetpack-my-jetpack' |
| 186 | ), |
| 187 | ), |
| 188 | ), |
| 189 | self::UPGRADED_TIER_SLUG => array( |
| 190 | 'included' => true, |
| 191 | 'description' => __( 'Included', 'jetpack-my-jetpack' ), |
| 192 | 'info' => array( |
| 193 | 'title' => __( 'Automatic Critical CSS regeneration', 'jetpack-my-jetpack' ), |
| 194 | 'content' => __( |
| 195 | '<p>It’s essential to regenerate Critical CSS to optimize your site speed whenever your HTML or CSS structure changes. Being on top of this can be tedious and time-consuming.</p> |
| 196 | <p>Boost’s cloud service can automatically detect when your site needs the Critical CSS regenerated, and perform this function behind the scenes without requiring you to monitor it manually.</p>', |
| 197 | 'jetpack-my-jetpack' |
| 198 | ), |
| 199 | ), |
| 200 | ), |
| 201 | ), |
| 202 | ), |
| 203 | array( |
| 204 | 'name' => __( 'Historical performance scores', 'jetpack-my-jetpack' ), |
| 205 | 'info' => array( |
| 206 | 'content' => __( |
| 207 | 'Get access to your historical performance scores and see advanced Core Web Vitals data.', |
| 208 | 'jetpack-my-jetpack' |
| 209 | ), |
| 210 | ), |
| 211 | 'tiers' => array( |
| 212 | self::FREE_TIER_SLUG => array( 'included' => false ), |
| 213 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 214 | ), |
| 215 | ), |
| 216 | array( |
| 217 | 'name' => __( 'Dedicated email support', 'jetpack-my-jetpack' ), |
| 218 | 'info' => array( |
| 219 | 'content' => __( |
| 220 | '<p>Paid customers get dedicated email support from our world-class Happiness Engineers to help with any issue.</p> |
| 221 | <p>All other questions are handled by our team as quickly as we are able to go through the WordPress support forum.</p>', |
| 222 | 'jetpack-my-jetpack' |
| 223 | ), |
| 224 | ), |
| 225 | 'tiers' => array( |
| 226 | self::FREE_TIER_SLUG => array( 'included' => false ), |
| 227 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 228 | ), |
| 229 | ), |
| 230 | array( |
| 231 | 'name' => __( 'Page Cache', 'jetpack-my-jetpack' ), |
| 232 | 'info' => array( |
| 233 | 'content' => __( |
| 234 | 'Page caching speeds up load times by storing a copy of each web page on the first visit, allowing subsequent visits to be served instantly. This reduces server load and improves user experience by delivering content faster, without waiting for the page to be generated again.', |
| 235 | 'jetpack-my-jetpack' |
| 236 | ), |
| 237 | ), |
| 238 | 'tiers' => array( |
| 239 | self::FREE_TIER_SLUG => array( 'included' => true ), |
| 240 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 241 | ), |
| 242 | ), |
| 243 | array( |
| 244 | 'name' => __( 'Image CDN Quality Settings', 'jetpack-my-jetpack' ), |
| 245 | 'info' => array( |
| 246 | 'content' => __( |
| 247 | 'Fine-tune image quality settings to your liking.', |
| 248 | 'jetpack-my-jetpack' |
| 249 | ), |
| 250 | ), |
| 251 | 'tiers' => array( |
| 252 | self::FREE_TIER_SLUG => array( 'included' => false ), |
| 253 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 254 | ), |
| 255 | ), |
| 256 | array( |
| 257 | 'name' => __( 'Image CDN Auto-Resize Lazy Images', 'jetpack-my-jetpack' ), |
| 258 | 'info' => array( |
| 259 | 'content' => __( |
| 260 | 'Optimizes lazy-loaded images by dynamically serving perfectly sized images for each device.', |
| 261 | 'jetpack-my-jetpack' |
| 262 | ), |
| 263 | ), |
| 264 | 'tiers' => array( |
| 265 | self::FREE_TIER_SLUG => array( 'included' => false ), |
| 266 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 267 | ), |
| 268 | ), |
| 269 | array( |
| 270 | 'name' => __( 'Image CDN', 'jetpack-my-jetpack' ), |
| 271 | 'info' => array( |
| 272 | 'content' => __( |
| 273 | 'Deliver images from Jetpack\'s Content Delivery Network. Automatically resizes your images to an appropriate size, converts them to modern efficient formats like WebP, and serves them from a worldwide network of servers.', |
| 274 | 'jetpack-my-jetpack' |
| 275 | ), |
| 276 | ), |
| 277 | 'tiers' => array( |
| 278 | self::FREE_TIER_SLUG => array( 'included' => true ), |
| 279 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 280 | ), |
| 281 | ), |
| 282 | array( |
| 283 | 'name' => __( 'Image guide', 'jetpack-my-jetpack' ), |
| 284 | 'info' => array( |
| 285 | 'content' => __( |
| 286 | 'Discover and fix images with a suboptimal resolution, aspect ratio, or file size, improving user experience and page speed.', |
| 287 | 'jetpack-my-jetpack' |
| 288 | ), |
| 289 | ), |
| 290 | 'tiers' => array( |
| 291 | self::FREE_TIER_SLUG => array( 'included' => true ), |
| 292 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 293 | ), |
| 294 | ), |
| 295 | array( |
| 296 | 'name' => __( 'Defer non-essential JavaScript', 'jetpack-my-jetpack' ), |
| 297 | 'info' => array( |
| 298 | 'content' => __( |
| 299 | 'Run non-essential JavaScript after the page has loaded so that styles and images can load more quickly.', |
| 300 | 'jetpack-my-jetpack' |
| 301 | ), |
| 302 | ), |
| 303 | 'tiers' => array( |
| 304 | self::FREE_TIER_SLUG => array( 'included' => true ), |
| 305 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 306 | ), |
| 307 | ), |
| 308 | array( |
| 309 | 'name' => __( 'Concatenate JS and CSS', 'jetpack-my-jetpack' ), |
| 310 | 'info' => array( |
| 311 | 'content' => __( |
| 312 | 'Boost your website performance by merging and compressing JavaScript and CSS files, reducing site loading time and number of requests.', |
| 313 | 'jetpack-my-jetpack' |
| 314 | ), |
| 315 | ), |
| 316 | 'tiers' => array( |
| 317 | self::FREE_TIER_SLUG => array( 'included' => true ), |
| 318 | self::UPGRADED_TIER_SLUG => array( 'included' => true ), |
| 319 | ), |
| 320 | ), |
| 321 | ); |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Get the URL the user is taken after purchasing the product through the checkout |
| 326 | * |
| 327 | * @return ?string |
| 328 | */ |
| 329 | public static function get_post_checkout_url() { |
| 330 | return self::get_manage_url(); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Get the product princing details |
| 335 | * |
| 336 | * @return array Pricing details |
| 337 | */ |
| 338 | public static function get_pricing_for_ui() { |
| 339 | return array( |
| 340 | 'tiers' => array( |
| 341 | self::FREE_TIER_SLUG => array( |
| 342 | 'available' => true, |
| 343 | 'is_free' => true, |
| 344 | ), |
| 345 | self::UPGRADED_TIER_SLUG => array_merge( |
| 346 | array( |
| 347 | 'available' => true, |
| 348 | 'wpcom_product_slug' => self::UPGRADED_TIER_PRODUCT_SLUG, |
| 349 | ), |
| 350 | Wpcom_Products::get_product_pricing( self::UPGRADED_TIER_PRODUCT_SLUG ) |
| 351 | ), |
| 352 | ), |
| 353 | ); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Get the URL where the user manages the product |
| 358 | * |
| 359 | * @return ?string |
| 360 | */ |
| 361 | public static function get_manage_url() { |
| 362 | return admin_url( 'admin.php?page=jetpack-boost' ); |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Activates the product by installing and activating its plugin |
| 367 | * |
| 368 | * @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. |
| 369 | * @return boolean|WP_Error |
| 370 | */ |
| 371 | public static function do_product_specific_activation( $current_result ) { |
| 372 | |
| 373 | $product_activation = parent::do_product_specific_activation( $current_result ); |
| 374 | |
| 375 | if ( is_wp_error( $product_activation ) && 'module_activation_failed' === $product_activation->get_error_code() ) { |
| 376 | // 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. |
| 377 | $product_activation = true; |
| 378 | } |
| 379 | |
| 380 | // We just "got started" in My Jetpack, so skip the in-plugin experience. |
| 381 | update_option( 'jb_get_started', false ); |
| 382 | |
| 383 | return $product_activation; |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Get the product-slugs of the paid plans for this product. |
| 388 | * (Do not include bundle plans, unless it's a bundle plan itself). |
| 389 | * |
| 390 | * @return array |
| 391 | */ |
| 392 | public static function get_paid_plan_product_slugs() { |
| 393 | return array( |
| 394 | 'jetpack_boost_yearly', |
| 395 | 'jetpack_boost_monthly', |
| 396 | 'jetpack_boost_bi_yearly', |
| 397 | ); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Return product bundles list |
| 402 | * that supports the product. |
| 403 | * |
| 404 | * @return boolean|array Products bundle list. |
| 405 | */ |
| 406 | public static function is_upgradable_by_bundle() { |
| 407 | return array( 'complete' ); |
| 408 | } |
| 409 | } |