Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
76.00% |
19 / 25 |
|
85.71% |
12 / 14 |
CRAP | |
0.00% |
0 / 1 |
| Activity_Log | |
78.26% |
18 / 23 |
|
85.71% |
12 / 14 |
19.97 | |
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% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_pricing_for_ui | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| is_module_active | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| is_active | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| is_activated | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| do_product_specific_activation | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
3.58 | |||
| deactivate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| is_plugin_installed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_manage_url | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| activate_plugin | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Feature: Activity Log |
| 4 | * |
| 5 | * @package my-jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\My_Jetpack\Products; |
| 9 | |
| 10 | use Automattic\Jetpack\Modules; |
| 11 | use Automattic\Jetpack\My_Jetpack\Module_Product; |
| 12 | use WP_Error; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class responsible for handling the Activity Log module. |
| 20 | */ |
| 21 | class Activity_Log extends Module_Product { |
| 22 | |
| 23 | /** |
| 24 | * The product slug |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | public static $slug = 'activity-log'; |
| 29 | |
| 30 | /** |
| 31 | * The slug of the plugin associated with this product. |
| 32 | * Activity Log is a feature available as part of the Jetpack plugin. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public static $plugin_slug = self::JETPACK_PLUGIN_SLUG; |
| 37 | |
| 38 | /** |
| 39 | * The Plugin file associated with Activity Log |
| 40 | * |
| 41 | * @var string|null |
| 42 | */ |
| 43 | public static $plugin_filename = self::JETPACK_PLUGIN_FILENAME; |
| 44 | |
| 45 | /** |
| 46 | * The Jetpack module name associated with this product |
| 47 | * |
| 48 | * @var string|null |
| 49 | */ |
| 50 | public static $module_name = 'activity-log'; |
| 51 | |
| 52 | /** |
| 53 | * The category of the product |
| 54 | * |
| 55 | * @var string |
| 56 | */ |
| 57 | public static $category = 'security'; |
| 58 | |
| 59 | /** |
| 60 | * Whether this module is a Jetpack feature |
| 61 | * |
| 62 | * @var boolean |
| 63 | */ |
| 64 | public static $is_feature = true; |
| 65 | |
| 66 | /** |
| 67 | * Whether this product requires a user connection |
| 68 | * |
| 69 | * @var boolean |
| 70 | */ |
| 71 | public static $requires_user_connection = true; |
| 72 | |
| 73 | /** |
| 74 | * Whether this product has a standalone plugin |
| 75 | * |
| 76 | * @var bool |
| 77 | */ |
| 78 | public static $has_standalone_plugin = false; |
| 79 | |
| 80 | /** |
| 81 | * Whether this product has a free offering. |
| 82 | * The free tier shows recent events; a paid plan unlocks the full history. |
| 83 | * |
| 84 | * @var bool |
| 85 | */ |
| 86 | public static $has_free_offering = true; |
| 87 | |
| 88 | /** |
| 89 | * Whether the product requires a plan to run |
| 90 | * The plan could be paid or free |
| 91 | * |
| 92 | * @var bool |
| 93 | */ |
| 94 | public static $requires_plan = false; |
| 95 | |
| 96 | /** |
| 97 | * Get the product name |
| 98 | * |
| 99 | * @return string |
| 100 | */ |
| 101 | public static function get_name() { |
| 102 | return 'Activity Log'; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get the product title |
| 107 | * |
| 108 | * @return string |
| 109 | */ |
| 110 | public static function get_title() { |
| 111 | return 'Activity Log'; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Get the internationalized product description |
| 116 | * |
| 117 | * @return string |
| 118 | */ |
| 119 | public static function get_description() { |
| 120 | return __( 'See what happened on your site and when', 'jetpack-my-jetpack' ); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Get the internationalized product long description |
| 125 | * |
| 126 | * @return string |
| 127 | */ |
| 128 | public static function get_long_description() { |
| 129 | return __( 'A record of every event on your site, so you can see what happened and roll back when something goes wrong', 'jetpack-my-jetpack' ); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Get the internationalized feature list |
| 134 | * |
| 135 | * @return array Activity Log features list |
| 136 | */ |
| 137 | public static function get_features() { |
| 138 | return array(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get the product pricing details |
| 143 | * |
| 144 | * @return array Pricing details |
| 145 | */ |
| 146 | public static function get_pricing_for_ui() { |
| 147 | return array( |
| 148 | 'available' => true, |
| 149 | 'is_free' => true, |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Checks whether the Activity Log module is switched on. |
| 155 | * |
| 156 | * Overrides the parent, which reads the module state through the Jetpack |
| 157 | * plugin and so reports every standalone install inactive. `Modules` reads |
| 158 | * the same `jetpack_active_modules` option with or without that plugin, and |
| 159 | * is the check `Jetpack_Activity_Log::initialize()` gates on. |
| 160 | * |
| 161 | * @return bool |
| 162 | */ |
| 163 | public static function is_module_active() { |
| 164 | return ( new Modules() )->is_active( static::$module_name ); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Checks whether the Product is active. |
| 169 | * |
| 170 | * The module state is the whole answer here: a site that serves the |
| 171 | * Activity Log page from a standalone plugin has no Jetpack plugin for the |
| 172 | * parent's `is_jetpack_plugin_active()` to find. |
| 173 | * |
| 174 | * @return boolean |
| 175 | */ |
| 176 | public static function is_active() { |
| 177 | return static::is_module_active(); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Checks whether the site has switched the product on. |
| 182 | * |
| 183 | * @return boolean |
| 184 | */ |
| 185 | public static function is_activated() { |
| 186 | return static::is_module_active(); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Activates the module. |
| 191 | * |
| 192 | * @param bool|WP_Error $plugin_activation Result of the top level activation actions. |
| 193 | * @return boolean|WP_Error |
| 194 | */ |
| 195 | public static function do_product_specific_activation( $plugin_activation ) { |
| 196 | if ( is_wp_error( $plugin_activation ) ) { |
| 197 | return $plugin_activation; |
| 198 | } |
| 199 | |
| 200 | if ( ! ( new Modules() )->activate( static::$module_name, false, false ) ) { |
| 201 | return new WP_Error( 'module_activation_failed', __( 'Error activating Jetpack module', 'jetpack-my-jetpack' ) ); |
| 202 | } |
| 203 | |
| 204 | return true; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Deactivates the module. |
| 209 | * |
| 210 | * @return boolean |
| 211 | */ |
| 212 | public static function deactivate() { |
| 213 | return ( new Modules() )->deactivate( static::$module_name ); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Checks whether the plugin is installed |
| 218 | * |
| 219 | * @return boolean |
| 220 | */ |
| 221 | public static function is_plugin_installed() { |
| 222 | return static::is_jetpack_plugin_installed(); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Get the URL where the user manages the product |
| 227 | * |
| 228 | * @return ?string |
| 229 | */ |
| 230 | public static function get_manage_url() { |
| 231 | return admin_url( 'admin.php?page=jetpack-activity-log' ); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Activates the Jetpack plugin |
| 236 | * |
| 237 | * @return null|WP_Error Null on success, WP_Error on invalid file. |
| 238 | */ |
| 239 | public static function activate_plugin(): ?WP_Error { |
| 240 | $plugin_filename = static::get_installed_plugin_filename( self::JETPACK_PLUGIN_SLUG ); |
| 241 | |
| 242 | if ( $plugin_filename ) { |
| 243 | return activate_plugin( $plugin_filename ); |
| 244 | } |
| 245 | } |
| 246 | } |