PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.1.5
Jetpack – WP Security, Backup, Speed, & Growth v3.1.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / monitor.php
monitor.php
154 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module Name: Monitor
4 * Module Description: Receive notifications from Jetpack if your site goes offline — and when it it returns.
5 * Sort Order: 28
6 * First Introduced: 2.6
7 * Requires Connection: Yes
8 * Auto Activate: No
9 */
10
11 add_action( 'jetpack_activate_module_monitor', array( Jetpack::init(), 'toggle_module_on_wpcom' ) );
12 add_action( 'jetpack_deactivate_module_monitor', array( Jetpack::init(), 'toggle_module_on_wpcom' ) );
13
14 class Jetpack_Monitor {
15
16 public $module = 'monitor';
17
18 function __construct() {
19 add_action( 'jetpack_modules_loaded', array( $this, 'jetpack_modules_loaded' ) );
20 add_action( 'jetpack_activate_module_monitor', array( $this, 'activate_module' ) );
21 }
22
23 public function activate_module() {
24 if ( Jetpack::is_user_connected() ) {
25 self::update_option_receive_jetpack_monitor_notification( true );
26 }
27 }
28
29 public function jetpack_modules_loaded() {
30 Jetpack::enable_module_configurable( $this->module );
31 Jetpack::module_configuration_load( $this->module, array( $this, 'jetpack_configuration_load' ) );
32 Jetpack::module_configuration_screen( $this->module, array( $this, 'jetpack_configuration_screen' ) );
33 }
34
35 public function jetpack_configuration_load() {
36 if ( Jetpack::is_user_connected() && ! self::is_active() ) {
37 Jetpack::deactivate_module( $this->module );
38 Jetpack::state( 'message', 'module_deactivated' );
39 wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
40 die();
41 }
42 if ( ! empty( $_POST['action'] ) && $_POST['action'] == 'monitor-save' ) {
43 check_admin_referer( 'monitor-settings' );
44 $this->update_option_receive_jetpack_monitor_notification( isset( $_POST['receive_jetpack_monitor_notification'] ) );
45 Jetpack::state( 'message', 'module_configured' );
46 wp_safe_redirect( Jetpack::module_configuration_url( $this->module ) );
47 }
48 }
49
50 public function jetpack_configuration_screen() {
51 ?>
52 <p><?php esc_html_e( 'Nobody likes downtime, and that\'s why Jetpack Monitor is on the job, keeping tabs on your site by checking it every five minutes. As soon as any downtime is detected, you will receive an email notification alerting you to the issue. That way you can act quickly, to get your site back online again!', 'jetpack' ); ?>
53 <p><?php esc_html_e( 'We’ll also let you know as soon as your site is up and running, so you can keep an eye on total downtime.', 'jetpack'); ?></p>
54 <div class="narrow">
55 <?php if ( Jetpack::is_user_connected() && current_user_can( 'manage_options' ) ) : ?>
56 <?php $user_email = Jetpack::get_connected_user_email(); ?>
57 <form method="post" id="monitor-settings">
58 <input type="hidden" name="action" value="monitor-save" />
59 <?php wp_nonce_field( 'monitor-settings' ); ?>
60
61 <table id="menu" class="form-table">
62 <tr>
63 <th scope="row">
64 <?php _e( 'Notifications', 'jetpack' ); ?>
65 </th>
66 <td>
67 <label for="receive_jetpack_monitor_notification">
68 <input type="checkbox" name="receive_jetpack_monitor_notification" id="receive_jetpack_monitor_notification" value="receive_jetpack_monitor_notification"<?php checked( $this->user_receives_notifications() ); ?> />
69 <span><?php _e( 'Receive Monitor Email Notifications.' , 'jetpack'); ?></span>
70 </label>
71 <p class="description"><?php printf( __( 'Emails will be sent to %s (<a href="%s">Edit</a>)', 'jetpack' ), $user_email, 'https://wordpress.com/settings/account/'); ?></p>
72 </td>
73 </tr>
74 </table>
75 <?php submit_button(); ?>
76 </form>
77 <?php else : ?>
78 <p><?php _e( 'This profile is not currently linked to a WordPress.com Profile.', 'jetpack' ); ?></p>
79 <?php endif; ?>
80 </div>
81 <?php
82 }
83
84 public function is_active() {
85 Jetpack::load_xml_rpc_client();
86 $xml = new Jetpack_IXR_Client( array(
87 'user_id' => get_current_user_id()
88 ) );
89 $xml->query( 'jetpack.monitor.isActive' );
90 if ( $xml->isError() ) {
91 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
92 }
93 return $xml->getResponse();
94 }
95
96 public function update_option_receive_jetpack_monitor_notification( $value ) {
97 Jetpack::load_xml_rpc_client();
98 $xml = new Jetpack_IXR_Client( array(
99 'user_id' => get_current_user_id()
100 ) );
101 $xml->query( 'jetpack.monitor.setNotifications', (bool) $value );
102
103 if ( $xml->isError() ) {
104 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
105 }
106 return true;
107 }
108
109 public function user_receives_notifications() {
110 Jetpack::load_xml_rpc_client();
111 $xml = new Jetpack_IXR_Client( array(
112 'user_id' => get_current_user_id()
113 ) );
114 $xml->query( 'jetpack.monitor.isUserInNotifications' );
115
116 if ( $xml->isError() ) {
117 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
118 }
119 return $xml->getResponse();
120 }
121
122 public function activate_monitor() {
123 Jetpack::load_xml_rpc_client();
124 $xml = new Jetpack_IXR_Client( array(
125 'user_id' => get_current_user_id()
126 ) );
127
128 $xml->query( 'jetpack.monitor.activate' );
129
130 if ( $xml->isError() ) {
131 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
132 }
133 return true;
134 }
135
136 public function deactivate_monitor() {
137 Jetpack::load_xml_rpc_client();
138 $xml = new Jetpack_IXR_Client( array(
139 'user_id' => get_current_user_id()
140 ) );
141
142 $xml->query( 'jetpack.monitor.deactivate' );
143
144 if ( $xml->isError() ) {
145 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
146 }
147 return true;
148 }
149
150 }
151
152 new Jetpack_Monitor;
153
154