'xmlrpc_data_response' ); return $methods; } /** * Handles the response for the jetpack.getHeartbeatData xmlrpc method * * @param array $params The parameters received in the request. * @return array $params all the stats that heartbeat handles. */ 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 ); } /** * Clear scheduled events * * @return void */ public function deactivate() { // Deal with the old pre-3.0 weekly one. $timestamp = wp_next_scheduled( 'jetpack_heartbeat' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'jetpack_heartbeat' ); } $timestamp = wp_next_scheduled( $this->cron_name ); wp_unschedule_event( $timestamp, $this->cron_name ); } /** * Interact with the Heartbeat * * ## OPTIONS * * inspect (default): Gets the list of data that is going to be sent in the heartbeat and the date/time of the last heartbeat * * @param array $args Arguments passed via CLI. * * @return void */ public function cli_callback( $args ) { $allowed_args = array( 'inspect', ); if ( isset( $args[0] ) && ! in_array( $args[0], $allowed_args, true ) ) { /* translators: %s is a command like "prompt" */ WP_CLI::error( sprintf( __( '%s is not a valid command.', 'jetpack-connection' ), $args[0] ) ); } $stats = self::generate_stats_array(); $formatted_stats = array(); foreach ( $stats as $stat_name => $bin ) { $formatted_stats[] = array( 'Stat name' => $stat_name, 'Bin' => $bin, ); } WP_CLI\Utils\format_items( 'table', $formatted_stats, array( 'Stat name', 'Bin' ) ); $last_heartbeat = Jetpack_Options::get_option( 'last_heartbeat' ); if ( $last_heartbeat ) { $last_date = gmdate( 'Y-m-d H:i:s', $last_heartbeat ); /* translators: %s is the full datetime of the last heart beat e.g. 2020-01-01 12:21:23 */ WP_CLI::line( sprintf( __( 'Last heartbeat sent at: %s', 'jetpack-connection' ), $last_date ) ); } } }