Jetpack_Monitor

Module Name: Monitor Module Description: Receive immediate notifications if your site goes down, 24/7.

Defined (1)

The class is defined in the following location(s).

/modules/monitor.php  
  1. class Jetpack_Monitor { 
  2.  
  3. public $module = 'monitor'; 
  4.  
  5. function __construct() { 
  6. add_action( 'jetpack_modules_loaded', array( $this, 'jetpack_modules_loaded' ) ); 
  7. add_action( 'jetpack_activate_module_monitor', array( $this, 'activate_module' ) ); 
  8.  
  9. public function activate_module() { 
  10. if ( Jetpack::is_user_connected() ) { 
  11. self::update_option_receive_jetpack_monitor_notification( true ); 
  12.  
  13. public function jetpack_modules_loaded() { 
  14. Jetpack::enable_module_configurable( $this->module ); 
  15. Jetpack::module_configuration_load( $this->module, array( $this, 'jetpack_configuration_load' ) ); 
  16. Jetpack::module_configuration_screen( $this->module, array( $this, 'jetpack_configuration_screen' ) ); 
  17.  
  18. public function jetpack_configuration_load() { 
  19. if ( Jetpack::is_user_connected() && ! self::is_active() ) { 
  20. Jetpack::deactivate_module( $this->module ); 
  21. Jetpack::state( 'message', 'module_deactivated' ); 
  22. wp_safe_redirect( Jetpack::admin_url( 'page=jetpack' ) ); 
  23. die(); 
  24. if ( ! empty( $_POST['action'] ) && $_POST['action'] == 'monitor-save' ) { 
  25. check_admin_referer( 'monitor-settings' ); 
  26. $this->update_option_receive_jetpack_monitor_notification( isset( $_POST['receive_jetpack_monitor_notification'] ) ); 
  27. Jetpack::state( 'message', 'module_configured' ); 
  28. wp_safe_redirect( Jetpack::module_configuration_url( $this->module ) ); 
  29.  
  30. public function jetpack_configuration_screen() { 
  31. ?> 
  32. <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' ); ?> 
  33. <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> 
  34. <div class="narrow"> 
  35. <?php if ( Jetpack::is_user_connected() && current_user_can( 'manage_options' ) ) : ?> 
  36. <?php $user_email = Jetpack::get_connected_user_email(); ?> 
  37. <form method="post" id="monitor-settings"> 
  38. <input type="hidden" name="action" value="monitor-save" /> 
  39. <?php wp_nonce_field( 'monitor-settings' ); ?> 
  40.  
  41. <table id="menu" class="form-table"> 
  42. <tr> 
  43. <th scope="row"> 
  44. <?php _e( 'Notifications', 'jetpack' ); ?> 
  45. </th> 
  46. <td> 
  47. <label for="receive_jetpack_monitor_notification"> 
  48. <input type="checkbox" name="receive_jetpack_monitor_notification" id="receive_jetpack_monitor_notification" value="receive_jetpack_monitor_notification"<?php checked( $this->user_receives_notifications() ); ?> /> 
  49. <span><?php _e( 'Receive Monitor Email Notifications.' , 'jetpack'); ?></span> 
  50. </label> 
  51. <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> 
  52. </td> 
  53. </tr> 
  54. </table> 
  55. <?php submit_button(); ?> 
  56. </form> 
  57. <?php else : ?> 
  58. <p><?php _e( 'This profile is not currently linked to a WordPress.com Profile.', 'jetpack' ); ?></p> 
  59. <?php endif; ?> 
  60. </div> 
  61. <?php 
  62.  
  63. public function is_active() { 
  64. Jetpack::load_xml_rpc_client(); 
  65. $xml = new Jetpack_IXR_Client( array( 
  66. 'user_id' => get_current_user_id() 
  67. ) ); 
  68. $xml->query( 'jetpack.monitor.isActive' ); 
  69. if ( $xml->isError() ) { 
  70. wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); 
  71. return $xml->getResponse(); 
  72.  
  73. public function update_option_receive_jetpack_monitor_notification( $value ) { 
  74. Jetpack::load_xml_rpc_client(); 
  75. $xml = new Jetpack_IXR_Client( array( 
  76. 'user_id' => get_current_user_id() 
  77. ) ); 
  78. $xml->query( 'jetpack.monitor.setNotifications', (bool) $value ); 
  79.  
  80. if ( $xml->isError() ) { 
  81. wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); 
  82. return true; 
  83.  
  84. public function user_receives_notifications() { 
  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.isUserInNotifications' ); 
  90.  
  91. if ( $xml->isError() ) { 
  92. wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); 
  93. return $xml->getResponse(); 
  94.  
  95. public function activate_monitor() { 
  96. Jetpack::load_xml_rpc_client(); 
  97. $xml = new Jetpack_IXR_Client( array( 
  98. 'user_id' => get_current_user_id() 
  99. ) ); 
  100.  
  101. $xml->query( 'jetpack.monitor.activate' ); 
  102.  
  103. if ( $xml->isError() ) { 
  104. wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); 
  105. return true; 
  106.  
  107. public function deactivate_monitor() { 
  108. Jetpack::load_xml_rpc_client(); 
  109. $xml = new Jetpack_IXR_Client( array( 
  110. 'user_id' => get_current_user_id() 
  111. ) ); 
  112.  
  113. $xml->query( 'jetpack.monitor.deactivate' ); 
  114.  
  115. if ( $xml->isError() ) { 
  116. wp_die( sprintf( '%s: %s', $xml->getErrorCode(), $xml->getErrorMessage() ) ); 
  117. return true; 
  118.