PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 3.7.5
Jetpack – WP Security, Backup, Speed, & Growth v3.7.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 in Jetpack – WP Security, Backup, Speed, & Growth 3.7.5, at modules/monitor.php

157 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: Reports on site downtime.
5 * Sort Order: 28
6 * Recommendation Order: 10
7 * First Introduced: 2.6
8 * Requires Connection: Yes
9 * Auto Activate: No
10 * Module Tags: Recommended
11 * Feature: Recommended, Performance-Security
12 */
13
14 add_action( 'jetpack_activate_module_monitor', array( Jetpack::init(), 'toggle_module_on_wpcom' ) );
15 add_action( 'jetpack_deactivate_module_monitor', array( Jetpack::init(), 'toggle_module_on_wpcom' ) );
16
17 class Jetpack_Monitor {
18
19 public $module = 'monitor';
20
21 function __construct() {
22 add_action( 'jetpack_modules_loaded', array( $this, 'jetpack_modules_loaded' ) );
23 add_action( 'jetpack_activate_module_monitor', array( $this, 'activate_module' ) );
24 }
25
26 public function activate_module() {
27 if ( Jetpack::is_user_connected() ) {
28 self::update_option_receive_jetpack_monitor_notification( true );
29 }
30 }
31
32 public function jetpack_modules_loaded() {
33 Jetpack::enable_module_configurable( $this->module );
34 Jetpack::module_configuration_load( $this->module, array( $this, 'jetpack_configuration_load' ) );
35 Jetpack::module_configuration_screen( $this->module, array( $this, 'jetpack_configuration_screen' ) );
36 }
37
38 public function jetpack_configuration_load() {
39 if ( Jetpack::is_user_connected() && ! self::is_active() ) {
40 Jetpack::deactivate_module( $this->module );
41 Jetpack::state( 'message', 'module_deactivated' );
42 wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) );
43 die();
44 }
45 if ( ! empty( $_POST['action'] ) && $_POST['action'] == 'monitor-save' ) {
46 check_admin_referer( 'monitor-settings' );
47 $this->update_option_receive_jetpack_monitor_notification( isset( $_POST['receive_jetpack_monitor_notification'] ) );
48 Jetpack::state( 'message', 'module_configured' );
49 wp_safe_redirect( Jetpack::module_configuration_url( $this->module ) );
50 }
51 }
52
53 public function jetpack_configuration_screen() {
54 ?>
55 <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' ); ?>
56 <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>
57 <div class="narrow">
58 <?php if ( Jetpack::is_user_connected() && current_user_can( 'manage_options' ) ) : ?>
59 <?php $user_email = Jetpack::get_connected_user_email(); ?>
60 <form method="post" id="monitor-settings">
61 <input type="hidden" name="action" value="monitor-save" />
62 <?php wp_nonce_field( 'monitor-settings' ); ?>
63
64 <table id="menu" class="form-table">
65 <tr>
66 <th scope="row">
67 <?php _e( 'Notifications', 'jetpack' ); ?>
68 </th>
69 <td>
70 <label for="receive_jetpack_monitor_notification">
71 <input type="checkbox" name="receive_jetpack_monitor_notification" id="receive_jetpack_monitor_notification" value="receive_jetpack_monitor_notification"<?php checked( $this->user_receives_notifications() ); ?> />
72 <span><?php _e( 'Receive Monitor Email Notifications.' , 'jetpack'); ?></span>
73 </label>
74 <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>
75 </td>
76 </tr>
77 </table>
78 <?php submit_button(); ?>
79 </form>
80 <?php else : ?>
81 <p><?php _e( 'This profile is not currently linked to a WordPress.com Profile.', 'jetpack' ); ?></p>
82 <?php endif; ?>
83 </div>
84 <?php
85 }
86
87 public function is_active() {
88 Jetpack::load_xml_rpc_client();
89 $xml = new Jetpack_IXR_Client( array(
90 'user_id' => get_current_user_id()
91 ) );
92 $xml->query( 'jetpack.monitor.isActive' );
93 if ( $xml->isError() ) {
94 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
95 }
96 return $xml->getResponse();
97 }
98
99 public function update_option_receive_jetpack_monitor_notification( $value ) {
100 Jetpack::load_xml_rpc_client();
101 $xml = new Jetpack_IXR_Client( array(
102 'user_id' => get_current_user_id()
103 ) );
104 $xml->query( 'jetpack.monitor.setNotifications', (bool) $value );
105
106 if ( $xml->isError() ) {
107 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
108 }
109 return true;
110 }
111
112 public function user_receives_notifications() {
113 Jetpack::load_xml_rpc_client();
114 $xml = new Jetpack_IXR_Client( array(
115 'user_id' => get_current_user_id()
116 ) );
117 $xml->query( 'jetpack.monitor.isUserInNotifications' );
118
119 if ( $xml->isError() ) {
120 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
121 }
122 return $xml->getResponse();
123 }
124
125 public function activate_monitor() {
126 Jetpack::load_xml_rpc_client();
127 $xml = new Jetpack_IXR_Client( array(
128 'user_id' => get_current_user_id()
129 ) );
130
131 $xml->query( 'jetpack.monitor.activate' );
132
133 if ( $xml->isError() ) {
134 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
135 }
136 return true;
137 }
138
139 public function deactivate_monitor() {
140 Jetpack::load_xml_rpc_client();
141 $xml = new Jetpack_IXR_Client( array(
142 'user_id' => get_current_user_id()
143 ) );
144
145 $xml->query( 'jetpack.monitor.deactivate' );
146
147 if ( $xml->isError() ) {
148 wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) );
149 }
150 return true;
151 }
152
153 }
154
155 new Jetpack_Monitor;
156
157