summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/class.jetpack-heartbeat.php')
-rw-r--r--plugins/jetpack/class.jetpack-heartbeat.php125
1 files changed, 38 insertions, 87 deletions
diff --git a/plugins/jetpack/class.jetpack-heartbeat.php b/plugins/jetpack/class.jetpack-heartbeat.php
index 8cd8a2a7..5af7f50a 100644
--- a/plugins/jetpack/class.jetpack-heartbeat.php
+++ b/plugins/jetpack/class.jetpack-heartbeat.php
@@ -1,6 +1,7 @@
<?php
use Automattic\Jetpack\Connection\Manager;
+use Automattic\Jetpack\Heartbeat;
class Jetpack_Heartbeat {
@@ -12,7 +13,13 @@ class Jetpack_Heartbeat {
*/
private static $instance = false;
- private $cron_name = 'jetpack_v2_heartbeat';
+ /**
+ * Holds the singleton instance of the proxied class
+ *
+ * @since 8.9.0
+ * @var Automattic\Jetpack\Heartbeat
+ */
+ private static $proxied_instance = false;
/**
* Singleton
@@ -23,7 +30,8 @@ class Jetpack_Heartbeat {
*/
public static function init() {
if ( ! self::$instance ) {
- self::$instance = new Jetpack_Heartbeat();
+ self::$instance = new Jetpack_Heartbeat();
+ self::$proxied_instance = Heartbeat::init();
}
return self::$instance;
@@ -36,70 +44,7 @@ class Jetpack_Heartbeat {
* @return Jetpack_Heartbeat
*/
private function __construct() {
- if ( ! Jetpack::is_active() ) {
- return;
- }
-
- // Schedule the task
- add_action( $this->cron_name, array( $this, 'cron_exec' ) );
-
- if ( ! wp_next_scheduled( $this->cron_name ) ) {
- // Deal with the old pre-3.0 weekly one.
- if ( $timestamp = wp_next_scheduled( 'jetpack_heartbeat' ) ) {
- wp_unschedule_event( $timestamp, 'jetpack_heartbeat' );
- }
-
- wp_schedule_event( time(), 'daily', $this->cron_name );
- }
-
- add_filter( 'jetpack_xmlrpc_methods', array( __CLASS__, 'jetpack_xmlrpc_methods' ) );
- }
-
- /**
- * Method that gets executed on the wp-cron call
- *
- * @since 2.3.3
- * @global string $wp_version
- */
- public function cron_exec() {
-
- $jetpack = Jetpack::init();
-
- /*
- * This should run daily. Figuring in for variances in
- * WP_CRON, don't let it run more than every 23 hours at most.
- *
- * i.e. if it ran less than 23 hours ago, fail out.
- */
- $last = (int) Jetpack_Options::get_option( 'last_heartbeat' );
- if ( $last && ( $last + DAY_IN_SECONDS - HOUR_IN_SECONDS > time() ) ) {
- return;
- }
-
- /*
- * Check for an identity crisis
- *
- * If one exists:
- * - Bump stat for ID crisis
- * - Email site admin about potential ID crisis
- */
-
- // Coming Soon!
-
- foreach ( self::generate_stats_array( 'v2-' ) as $key => $value ) {
- $jetpack->stat( $key, $value );
- }
-
- Jetpack_Options::update_option( 'last_heartbeat', time() );
-
- $jetpack->do_stats( 'server_side' );
-
- /**
- * Fires when we synchronize all registered options on heartbeat.
- *
- * @since 3.3.0
- */
- do_action( 'jetpack_heartbeat' );
+ add_filter( 'jetpack_heartbeat_stats_array', array( $this, 'add_stats_to_heartbeat' ) );
}
/**
@@ -115,9 +60,9 @@ class Jetpack_Heartbeat {
$return[ "{$prefix}version" ] = JETPACK__VERSION;
$return[ "{$prefix}wp-version" ] = get_bloginfo( 'version' );
$return[ "{$prefix}php-version" ] = PHP_VERSION;
- $return[ "{$prefix}branch" ] = floatval( JETPACK__VERSION );
- $return[ "{$prefix}wp-branch" ] = floatval( get_bloginfo( 'version' ) );
- $return[ "{$prefix}php-branch" ] = floatval( PHP_VERSION );
+ $return[ "{$prefix}branch" ] = (float) JETPACK__VERSION;
+ $return[ "{$prefix}wp-branch" ] = (float) get_bloginfo( 'version' );
+ $return[ "{$prefix}php-branch" ] = (float) PHP_VERSION;
$return[ "{$prefix}public" ] = Jetpack_Options::get_option( 'public' );
$return[ "{$prefix}ssl" ] = Jetpack::permit_ssl();
$return[ "{$prefix}is-https" ] = is_ssl() ? 'https' : 'http';
@@ -131,6 +76,16 @@ class Jetpack_Heartbeat {
}
$return[ "{$prefix}manage-enabled" ] = true;
+ if ( function_exists( 'get_space_used' ) ) { // Only available in multisite.
+ $space_used = get_space_used();
+ } else {
+ // This is the same as `get_space_used`, except it does not apply the short-circuit filter.
+ $upload_dir = wp_upload_dir();
+ $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
+ }
+
+ $return[ "{$prefix}space-used" ] = $space_used;
+
$xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() );
if ( $xmlrpc_errors ) {
$return[ "{$prefix}xmlrpc-errors" ] = implode( ',', array_keys( $xmlrpc_errors ) );
@@ -162,27 +117,23 @@ class Jetpack_Heartbeat {
return $return;
}
- public static function jetpack_xmlrpc_methods( $methods ) {
- $methods['jetpack.getHeartbeatData'] = array( __CLASS__, 'xmlrpc_data_response' );
- return $methods;
- }
-
- public static function xmlrpc_data_response( $params = array() ) {
- // The WordPress XML-RPC server sets a default param of array()
- // if no argument is passed on the request and the method handlers get this array in $params.
- // generate_stats_array() needs a string as first argument.
- $params = empty( $params ) ? '' : $params;
- return self::generate_stats_array( $params );
- }
+ /**
+ * Add Jetpack Stats array to Heartbeat if Jetpack is connected
+ *
+ * @since 8.9.0
+ *
+ * @param array $stats Jetpack Heartbeat stats.
+ * @return array $stats
+ */
+ public function add_stats_to_heartbeat( $stats ) {
- public function deactivate() {
- // Deal with the old pre-3.0 weekly one.
- if ( $timestamp = wp_next_scheduled( 'jetpack_heartbeat' ) ) {
- wp_unschedule_event( $timestamp, 'jetpack_heartbeat' );
+ if ( ! Jetpack::is_connection_ready() ) {
+ return $stats;
}
- $timestamp = wp_next_scheduled( $this->cron_name );
- wp_unschedule_event( $timestamp, $this->cron_name );
+ $jetpack_stats = self::generate_stats_array();
+
+ return array_merge( $stats, $jetpack_stats );
}
}