| @@ -1,5 +1,5 @@ | ||
| 1 | -<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | |
| 1 | +<?php | |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Monitor |
| 4 | 4 | * Module Description: Jetpack’s downtime monitoring will continuously watch your site and alert you the moment that downtime is detected. |
| 5 | 5 | * Sort Order: 28 |
| @@ -10,10 +10,8 @@ | ||
| 10 | 10 | * Auto Activate: No |
| 11 | 11 | * Module Tags: Recommended |
| 12 | 12 | * Feature: Security |
| 13 | 13 | * Additional Search Queries: monitor, uptime, downtime, monitoring, maintenance, maintenance mode, offline, site is down, site down, down, repair, error |
| 14 | - * | |
| 15 | - * @package automattic/jetpack | |
| 16 | 14 | */ |
| 17 | 15 | |
| 18 | 16 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 19 | 17 | |
| @@ -21,28 +19,15 @@ | ||
| 21 | 19 | * Class Jetpack_Monitor |
| 22 | 20 | */ |
| 23 | 21 | class Jetpack_Monitor { |
| 24 | 22 | |
| 25 | - /** | |
| 26 | - * Name of the module. | |
| 27 | - * | |
| 28 | - * @var string Name of module. | |
| 29 | - */ | |
| 30 | 23 | public $module = 'monitor'; |
| 31 | 24 | |
| 32 | - /** | |
| 33 | - * Constructor. | |
| 34 | - */ | |
| 35 | - public function __construct() { | |
| 25 | + function __construct() { | |
| 36 | 26 | add_action( 'jetpack_modules_loaded', array( $this, 'jetpack_modules_loaded' ) ); |
| 37 | 27 | add_action( 'jetpack_activate_module_monitor', array( $this, 'activate_module' ) ); |
| 38 | 28 | } |
| 39 | 29 | |
| 40 | - /** | |
| 41 | - * Runs upon module activation. | |
| 42 | - * | |
| 43 | - * @return void | |
| 44 | - */ | |
| 45 | 30 | public function activate_module() { |
| 46 | 31 | if ( ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ) { |
| 47 | 32 | self::update_option_receive_jetpack_monitor_notification( true ); |
| 48 | 33 | } |
| @@ -47,13 +32,8 @@ | ||
| 47 | 32 | self::update_option_receive_jetpack_monitor_notification( true ); |
| 48 | 33 | } |
| 49 | 34 | } |
| 50 | 35 | |
| 51 | - /** | |
| 52 | - * Runs on the jetpack_modules_loaded hook to enable configuation. | |
| 53 | - * | |
| 54 | - * @return void | |
| 55 | - */ | |
| 56 | 36 | public function jetpack_modules_loaded() { |
| 57 | 37 | Jetpack::enable_module_configurable( $this->module ); |
| 58 | 38 | } |
| 59 | 39 | |
| @@ -64,17 +44,15 @@ | ||
| 64 | 44 | * |
| 65 | 45 | * @return bool |
| 66 | 46 | */ |
| 67 | 47 | public function update_option_receive_jetpack_monitor_notification( $value ) { |
| 68 | - $xml = new Jetpack_IXR_Client( | |
| 69 | - array( | |
| 70 | - 'user_id' => get_current_user_id(), | |
| 71 | - ) | |
| 72 | - ); | |
| 48 | + $xml = new Jetpack_IXR_Client( array( | |
| 49 | + 'user_id' => get_current_user_id() | |
| 50 | + ) ); | |
| 73 | 51 | $xml->query( 'jetpack.monitor.setNotifications', (bool) $value ); |
| 74 | 52 | |
| 75 | 53 | if ( $xml->isError() ) { |
| 76 | - wp_die( sprintf( '%s: %s', esc_html( $xml->getErrorCode() ), esc_html( $xml->getErrorMessage() ) ) ); | |
| 54 | + wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); | |
| 77 | 55 | } |
| 78 | 56 | |
| 79 | 57 | // To be used only in Jetpack_Core_Json_Api_Endpoints::get_remote_value. |
| 80 | 58 | update_option( 'monitor_receive_notifications', (bool) $value ); |
| @@ -91,19 +69,17 @@ | ||
| 91 | 69 | * @param bool $die_on_error Whether to issue a wp_die when an error occurs or return a WP_Error object. |
| 92 | 70 | * |
| 93 | 71 | * @return boolean|WP_Error |
| 94 | 72 | */ |
| 95 | - public static function user_receives_notifications( $die_on_error = true ) { | |
| 96 | - $xml = new Jetpack_IXR_Client( | |
| 97 | - array( | |
| 98 | - 'user_id' => get_current_user_id(), | |
| 99 | - ) | |
| 100 | - ); | |
| 73 | + static function user_receives_notifications( $die_on_error = true ) { | |
| 74 | + $xml = new Jetpack_IXR_Client( array( | |
| 75 | + 'user_id' => get_current_user_id() | |
| 76 | + ) ); | |
| 101 | 77 | $xml->query( 'jetpack.monitor.isUserInNotifications' ); |
| 102 | 78 | |
| 103 | 79 | if ( $xml->isError() ) { |
| 104 | 80 | if ( $die_on_error ) { |
| 105 | - wp_die( sprintf( '%s: %s', esc_html( $xml->getErrorCode() ), esc_html( $xml->getErrorMessage() ) ), 400 ); | |
| 81 | + wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); | |
| 106 | 82 | } else { |
| 107 | 83 | return new WP_Error( $xml->getErrorCode(), $xml->getErrorMessage(), array( 'status' => 400 ) ); |
| 108 | 84 | } |
| 109 | 85 | } |
| @@ -109,13 +85,13 @@ | ||
| 109 | 85 | } |
| 110 | 86 | return $xml->getResponse(); |
| 111 | 87 | } |
| 112 | 88 | |
| 113 | - /** | |
| 89 | + /* | |
| 114 | 90 | * Returns date of the last downtime. |
| 115 | 91 | * |
| 116 | 92 | * @since 4.0.0 |
| 117 | - * @return string date in YYYY-MM-DD HH:mm:ss format | |
| 93 | + * @return date in YYYY-MM-DD HH:mm:ss format | |
| 118 | 94 | */ |
| 119 | 95 | public function monitor_get_last_downtime() { |
| 120 | 96 | $xml = new Jetpack_IXR_Client(); |
| 121 | 97 | |
| @@ -131,5 +107,5 @@ | ||
| 131 | 107 | } |
| 132 | 108 | |
| 133 | 109 | } |
| 134 | 110 | |
| 135 | -new Jetpack_Monitor(); | |
| 111 | +new Jetpack_Monitor; | |