PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 10.2
Jetpack – WP Security, Backup, Speed, & Growth v10.2
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 / class.jetpack-heartbeat.php

class.jetpack-heartbeat.php in Jetpack – WP Security, Backup, Speed, & Growth 10.2, at class.jetpack-heartbeat.php

197 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Automattic\Jetpack\Connection\Manager;
4 use Automattic\Jetpack\Heartbeat;
5
6 class Jetpack_Heartbeat {
7
8 /**
9 * Holds the singleton instance of this class
10 *
11 * @since 2.3.3
12 * @var Jetpack_Heartbeat
13 */
14 private static $instance = false;
15
16 /**
17 * Holds the singleton instance of the proxied class
18 *
19 * @since 8.9.0
20 * @var Automattic\Jetpack\Heartbeat
21 */
22 private static $proxied_instance = false;
23
24 /**
25 * Singleton
26 *
27 * @since 2.3.3
28 * @static
29 * @return Jetpack_Heartbeat
30 */
31 public static function init() {
32 if ( ! self::$instance ) {
33 self::$instance = new Jetpack_Heartbeat();
34 self::$proxied_instance = Heartbeat::init();
35 }
36
37 return self::$instance;
38 }
39
40 /**
41 * Constructor for singleton
42 *
43 * @since 2.3.3
44 * @return Jetpack_Heartbeat
45 */
46 private function __construct() {
47 add_filter( 'jetpack_heartbeat_stats_array', array( $this, 'add_stats_to_heartbeat' ) );
48 }
49
50 /**
51 * Method that gets executed on the wp-cron call
52 *
53 * @deprecated since 8.9.0
54 * @see Automattic\Jetpack\Heartbeat::cron_exec()
55 *
56 * @since 2.3.3
57 * @global string $wp_version
58 */
59 public function cron_exec() {
60 _deprecated_function( __METHOD__, 'jetpack-8.9.0', 'Automattic\\Jetpack\\Heartbeat::cron_exec' );
61 return self::$proxied_instance->cron_exec();
62
63 }
64
65 /**
66 * Generates heartbeat stats data.
67 *
68 * @param string $prefix Prefix to add before stats identifier.
69 *
70 * @return array The stats array.
71 */
72 public static function generate_stats_array( $prefix = '' ) {
73 $return = array();
74
75 $return[ "{$prefix}version" ] = JETPACK__VERSION;
76 $return[ "{$prefix}wp-version" ] = get_bloginfo( 'version' );
77 $return[ "{$prefix}php-version" ] = PHP_VERSION;
78 $return[ "{$prefix}branch" ] = (float) JETPACK__VERSION;
79 $return[ "{$prefix}wp-branch" ] = (float) get_bloginfo( 'version' );
80 $return[ "{$prefix}php-branch" ] = (float) PHP_VERSION;
81 $return[ "{$prefix}public" ] = Jetpack_Options::get_option( 'public' );
82 $return[ "{$prefix}ssl" ] = Jetpack::permit_ssl();
83 $return[ "{$prefix}is-https" ] = is_ssl() ? 'https' : 'http';
84 $return[ "{$prefix}language" ] = get_bloginfo( 'language' );
85 $return[ "{$prefix}charset" ] = get_bloginfo( 'charset' );
86 $return[ "{$prefix}is-multisite" ] = is_multisite() ? 'multisite' : 'singlesite';
87 $return[ "{$prefix}identitycrisis" ] = Jetpack::check_identity_crisis() ? 'yes' : 'no';
88 $return[ "{$prefix}plugins" ] = implode( ',', Jetpack::get_active_plugins() );
89 if ( function_exists( 'get_mu_plugins' ) ) {
90 $return[ "{$prefix}mu-plugins" ] = implode( ',', array_keys( get_mu_plugins() ) );
91 }
92 $return[ "{$prefix}manage-enabled" ] = true;
93
94 if ( function_exists( 'get_space_used' ) ) { // Only available in multisite.
95 $space_used = get_space_used();
96 } else {
97 // This is the same as `get_space_used`, except it does not apply the short-circuit filter.
98 $upload_dir = wp_upload_dir();
99 $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
100 }
101
102 $return[ "{$prefix}space-used" ] = $space_used;
103
104 $xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() );
105 if ( $xmlrpc_errors ) {
106 $return[ "{$prefix}xmlrpc-errors" ] = implode( ',', array_keys( $xmlrpc_errors ) );
107 Jetpack_Options::delete_option( 'xmlrpc_errors' );
108 }
109
110 // Missing the connection owner?
111 $connection_manager = new Manager();
112 $return[ "{$prefix}missing-owner" ] = $connection_manager->is_missing_connection_owner();
113
114 // is-multi-network can have three values, `single-site`, `single-network`, and `multi-network`.
115 $return[ "{$prefix}is-multi-network" ] = 'single-site';
116 if ( is_multisite() ) {
117 $return[ "{$prefix}is-multi-network" ] = Jetpack::is_multi_network() ? 'multi-network' : 'single-network';
118 }
119
120 if ( ! empty( $_SERVER['SERVER_ADDR'] ) || ! empty( $_SERVER['LOCAL_ADDR'] ) ) {
121 $ip = ! empty( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
122 $ip_arr = array_map( 'intval', explode( '.', $ip ) );
123 if ( 4 === count( $ip_arr ) ) {
124 $return[ "{$prefix}ip-2-octets" ] = implode( '.', array_slice( $ip_arr, 0, 2 ) );
125 }
126 }
127
128 foreach ( Jetpack::get_available_modules() as $slug ) {
129 $return[ "{$prefix}module-{$slug}" ] = Jetpack::is_module_active( $slug ) ? 'on' : 'off';
130 }
131
132 return $return;
133 }
134
135 /**
136 * Registers jetpack.getHeartbeatData xmlrpc method
137 *
138 * @deprecated since 8.9.0
139 * @see Automattic\Jetpack\Heartbeat::jetpack_xmlrpc_methods()
140 *
141 * @param array $methods The list of methods to be filtered.
142 * @return array $methods
143 */
144 public static function jetpack_xmlrpc_methods( $methods ) {
145 _deprecated_function( __METHOD__, 'jetpack-8.9.0', 'Automattic\\Jetpack\\Heartbeat::jetpack_xmlrpc_methods' );
146 return Heartbeat::jetpack_xmlrpc_methods( $methods );
147 }
148
149 /**
150 * Handles the response for the jetpack.getHeartbeatData xmlrpc method
151 *
152 * @deprecated since 8.9.0
153 * @see Automattic\Jetpack\Heartbeat::xmlrpc_data_response()
154 *
155 * @param array $params The parameters received in the request.
156 * @return array $params all the stats that heartbeat handles.
157 */
158 public static function xmlrpc_data_response( $params = array() ) {
159 _deprecated_function( __METHOD__, 'jetpack-8.9.0', 'Automattic\\Jetpack\\Heartbeat::xmlrpc_data_response' );
160 return Heartbeat::xmlrpc_data_response( $params );
161 }
162
163 /**
164 * Clear scheduled events
165 *
166 * @deprecated since 8.9.0
167 * @see Automattic\Jetpack\Heartbeat::deactivate()
168 *
169 * @return void
170 */
171 public function deactivate() {
172 // Cronjobs are now handled by the Heartbeat package and we don't want to deactivate it here.
173 // We are adding jetpack stats to the heartbeat only if the connection is available. so we don't need to disable the cron when disconnecting.
174 _deprecated_function( __METHOD__, 'jetpack-8.9.0', 'Automattic\\Jetpack\\Heartbeat::deactivate' );
175 }
176
177 /**
178 * Add Jetpack Stats array to Heartbeat if Jetpack is connected
179 *
180 * @since 8.9.0
181 *
182 * @param array $stats Jetpack Heartbeat stats.
183 * @return array $stats
184 */
185 public function add_stats_to_heartbeat( $stats ) {
186
187 if ( ! Jetpack::is_connection_ready() ) {
188 return $stats;
189 }
190
191 $jetpack_stats = self::generate_stats_array();
192
193 return array_merge( $stats, $jetpack_stats );
194 }
195
196 }
197