1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
<?php
class Jetpack_Heartbeat {
/**
* Holds the singleton instance of this class
*
* @since 2.3.3
* @var Jetpack_Heartbeat
*/
static $instance = false;
private $cron_name = 'jetpack_heartbeat';
/**
* Singleton
*
* @since 2.3.3
* @static
* @return Jetpack_Heartbeat
*/
public static function init() {
if ( ! self::$instance ) {
self::$instance = new Jetpack_Heartbeat;
}
return self::$instance;
}
/**
* Constructor for singleton
*
* @since 2.3.3
* @return Jetpack_Heartbeat
*/
private function __construct() {
// Add weekly interval for wp-cron
add_filter('cron_schedules', array( $this, 'add_cron_intervals' ) );
// Schedule the task
add_action( $this->cron_name, array( $this, 'cron_exec' ) );
if (!wp_next_scheduled( $this->cron_name ) ) {
wp_schedule_event( time(), 'jetpack_weekly', $this->cron_name );
}
}
/**
* Method that gets executed on the wp-cron call
*
* @since 2.3.3
* @global string $wp_version
*/
public function cron_exec() {
/*
* Check for an identity crisis
*
* If one exists:
* - Bump stat for ID crisis
* - Email site admin about potential ID crisis
*/
/**
* Setup an array of items that will eventually be stringified
* and sent off to the Jetpack API
*
* Associative array with format group => values
* - values should be an array that will be imploded to a string
*/
$jetpack = Jetpack::init();
$jetpack->stat( 'active-modules', implode( ',', $jetpack->get_active_modules() ) );
$jetpack->stat( 'active', JETPACK__VERSION );
$jetpack->stat( 'wp-version', get_bloginfo( 'version' ) );
$jetpack->stat( 'php-version', PHP_VERSION );
$jetpack->stat( 'ssl', $jetpack->permit_ssl() );
$jetpack->stat( 'language', get_bloginfo( 'language' ) );
$jetpack->stat( 'charset', get_bloginfo( 'charset' ) );
$jetpack->stat( 'qty-posts', wp_count_posts()->publish );
$jetpack->stat( 'qty-pages', wp_count_posts( 'page' )->publish );
$jetpack->stat( 'qty-comments', wp_count_comments()->approved );
$jetpack->stat( 'is-multisite', is_multisite() ? 'multisite' : 'singlesite' );
$jetpack->stat( 'identitycrisis', Jetpack::check_identity_crisis( 1 ) ? 'yes' : 'no' );
// Only check a few plugins, to see if they're currently active.
$plugins_to_check = array(
'vaultpress/vaultpress.php',
'akismet/akismet.php',
'wp-super-cache/wp-cache.php',
);
$plugins = array_intersect( $plugins_to_check, get_option( 'active_plugins', array() ) );
foreach( $plugins as $plugin ) {
$jetpack->stat( 'plugins', $plugin );
}
$jetpack->do_stats( 'server_side' );
}
/**
* Adds additional Jetpack specific intervals to wp-cron
*
* @since 2.3.3
* @return array
*/
public function add_cron_intervals( $schedules ) {
$schedules['jetpack_weekly'] = array(
'interval' => WEEK_IN_SECONDS,
'display' => __( 'Jetpack weekly', 'jetpack' ),
);
return $schedules;
}
public function deactivate() {
$timestamp = wp_next_scheduled( $this->cron_name );
wp_unschedule_event( $timestamp, $this->cron_name );
}
}
|