Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
59.46% |
22 / 37 |
|
40.00% |
6 / 15 |
CRAP | |
0.00% |
0 / 1 |
| Scan | |
60.00% |
21 / 35 |
|
40.00% |
6 / 15 |
38.74 | |
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% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| get_pricing_for_ui | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| get_wpcom_product_slug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| is_active | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| do_product_specific_activation | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| is_module_active | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_paid_plan_product_slugs | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| is_upgradable_by_bundle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_post_activation_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_manage_url | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_post_checkout_url | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Scan product |
| 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 Automattic\Jetpack\Redirect; |
| 13 | use WP_Error; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit( 0 ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Class responsible for handling the Scan product |
| 21 | */ |
| 22 | class Scan extends Module_Product { |
| 23 | |
| 24 | /** |
| 25 | * The product slug |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | public static $slug = 'scan'; |
| 30 | |
| 31 | /** |
| 32 | * The Jetpack module name |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public static $module_name = 'scan'; |
| 37 | |
| 38 | /** |
| 39 | * The category of the product |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public static $category = 'security'; |
| 44 | |
| 45 | /** |
| 46 | * The feature slug that identifies the paid plan |
| 47 | * |
| 48 | * @var string |
| 49 | */ |
| 50 | public static $feature_identifying_paid_plan = 'scan'; |
| 51 | |
| 52 | /** |
| 53 | * Get the product name |
| 54 | * |
| 55 | * @return string |
| 56 | */ |
| 57 | public static function get_name() { |
| 58 | return 'Scan'; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get the product title |
| 63 | * |
| 64 | * @return string |
| 65 | */ |
| 66 | public static function get_title() { |
| 67 | return 'Jetpack Scan'; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get the internationalized product description |
| 72 | * |
| 73 | * @return string |
| 74 | */ |
| 75 | public static function get_description() { |
| 76 | return __( 'Around‑the‑clock web application firewall, and automated malware scanning.', 'jetpack-my-jetpack' ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get the internationalized product long description |
| 81 | * |
| 82 | * @return string |
| 83 | */ |
| 84 | public static function get_long_description() { |
| 85 | return __( 'Automatic scanning and one-click fixes keep your site one step ahead of security threats and malware.', 'jetpack-my-jetpack' ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get the internationalized features list |
| 90 | * |
| 91 | * @return array Scan features list |
| 92 | */ |
| 93 | public static function get_features() { |
| 94 | return array( |
| 95 | _x( 'Automated daily scanning', 'Scan Product Feature', 'jetpack-my-jetpack' ), |
| 96 | _x( 'One-click fixes for most issues', 'Scan Product Feature', 'jetpack-my-jetpack' ), |
| 97 | _x( 'Instant email notifications', 'Scan Product Feature', 'jetpack-my-jetpack' ), |
| 98 | _x( 'Access to latest Firewall rules', 'Scan Product Feature', 'jetpack-my-jetpack' ), |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get the product princing details |
| 104 | * |
| 105 | * @return array Pricing details |
| 106 | */ |
| 107 | public static function get_pricing_for_ui() { |
| 108 | return array_merge( |
| 109 | array( |
| 110 | 'available' => true, |
| 111 | 'wpcom_product_slug' => static::get_wpcom_product_slug(), |
| 112 | ), |
| 113 | Wpcom_Products::get_product_pricing( static::get_wpcom_product_slug() ) |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Get the WPCOM product slug used to make the purchase |
| 119 | * |
| 120 | * @return ?string |
| 121 | */ |
| 122 | public static function get_wpcom_product_slug() { |
| 123 | return 'jetpack_scan'; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Checks whether the Product is active |
| 128 | * |
| 129 | * Scan is not actually a module. Activation takes place on WPCOM. So lets consider it active if jetpack is active and has the plan. |
| 130 | * |
| 131 | * @return boolean |
| 132 | */ |
| 133 | public static function is_active() { |
| 134 | return static::is_jetpack_plugin_active(); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Activates the product by installing and activating its plugin |
| 139 | * |
| 140 | * @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. |
| 141 | * @return boolean|\WP_Error |
| 142 | */ |
| 143 | public static function do_product_specific_activation( $current_result ) { |
| 144 | |
| 145 | $product_activation = parent::do_product_specific_activation( $current_result ); |
| 146 | |
| 147 | if ( is_wp_error( $product_activation ) && 'module_activation_failed' === $product_activation->get_error_code() ) { |
| 148 | // Scan is not a module. There's nothing in the plugin to be activated, so it's ok to fail to activate the module. |
| 149 | $product_activation = true; |
| 150 | } |
| 151 | |
| 152 | return $product_activation; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Checks whether the Jetpack module is active |
| 157 | * |
| 158 | * Scan is not a module. Nothing needs to be active. Let's always consider it active. |
| 159 | * |
| 160 | * @return bool |
| 161 | */ |
| 162 | public static function is_module_active() { |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get the product-slugs of the paid plans for this product. |
| 168 | * (Do not include bundle plans, unless it's a bundle plan itself). |
| 169 | * |
| 170 | * @return array |
| 171 | */ |
| 172 | public static function get_paid_plan_product_slugs() { |
| 173 | return array( |
| 174 | 'jetpack_scan', |
| 175 | 'jetpack_scan_monthly', |
| 176 | 'jetpack_scan_bi_yearly', |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Return product bundles list |
| 182 | * that supports the product. |
| 183 | * |
| 184 | * @return boolean|array Products bundle list. |
| 185 | */ |
| 186 | public static function is_upgradable_by_bundle() { |
| 187 | return array( 'security', 'complete' ); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Get the URL the user is taken after activating the product |
| 192 | * |
| 193 | * @return ?string |
| 194 | */ |
| 195 | public static function get_post_activation_url() { |
| 196 | return ''; // stay in My Jetpack page. |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Get the URL where the user manages the product |
| 201 | * |
| 202 | * @return ?string |
| 203 | */ |
| 204 | public static function get_manage_url() { |
| 205 | return Redirect::get_url( 'my-jetpack-manage-scan' ); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Get the URL where the user should be redirected after checkout |
| 210 | */ |
| 211 | public static function get_post_checkout_url() { |
| 212 | if ( static::is_jetpack_plugin_active() ) { |
| 213 | return 'admin.php?page=jetpack#/recommendations'; |
| 214 | } |
| 215 | |
| 216 | // If Jetpack is not active, it means that the user has another standalone plugin active |
| 217 | // and it follows the `Protect` plugin flow instead of `Scan` so for now it would be safe |
| 218 | // to return null and let the user go back to the My Jetpack page. |
| 219 | return null; |
| 220 | } |
| 221 | } |