Jetpack::jetpack_check_heartbeat_data PHP Method

jetpack_check_heartbeat_data() public static method

Organizes the heartbeat data by severity. For example, if the site is in an ID crisis, it will be in the $filtered_data['bad'] array. Data will be added to "caution" array, if it either: - Out of date Jetpack version - Out of date WP version - Out of date PHP version $return array $filtered_data
public static jetpack_check_heartbeat_data ( )
    public static function jetpack_check_heartbeat_data()
    {
        $raw_data = Jetpack_Heartbeat::generate_stats_array();
        $good = array();
        $caution = array();
        $bad = array();
        foreach ($raw_data as $stat => $value) {
            // Check jetpack version
            if ('version' == $stat) {
                if (version_compare($value, JETPACK__VERSION, '<')) {
                    $caution[$stat] = $value . " - min supported is " . JETPACK__VERSION;
                    continue;
                }
            }
            // Check WP version
            if ('wp-version' == $stat) {
                if (version_compare($value, JETPACK__MINIMUM_WP_VERSION, '<')) {
                    $caution[$stat] = $value . " - min supported is " . JETPACK__MINIMUM_WP_VERSION;
                    continue;
                }
            }
            // Check PHP version
            if ('php-version' == $stat) {
                if (version_compare(PHP_VERSION, '5.2.4', '<')) {
                    $caution[$stat] = $value . " - min supported is 5.2.4";
                    continue;
                }
            }
            // Check ID crisis
            if ('identitycrisis' == $stat) {
                if ('yes' == $value) {
                    $bad[$stat] = $value;
                    continue;
                }
            }
            // The rest are good :)
            $good[$stat] = $value;
        }
        $filtered_data = array('good' => $good, 'caution' => $caution, 'bad' => $bad);
        return $filtered_data;
    }

Usage Example

Esempio n. 1
0
 /**
  * Get Jetpack Details
  *
  * ## OPTIONS
  *
  * empty: Leave it empty for basic stats
  *
  * full: View full stats.  It's the data from the heartbeat
  *
  * ## EXAMPLES
  *
  * wp jetpack status
  * wp jetpack status full
  *
  */
 public function status($args, $assoc_args)
 {
     if (!Jetpack::is_active()) {
         WP_CLI::error(__('Jetpack is not currently connected to WordPress.com', 'jetpack'));
     }
     if (isset($args[0]) && 'full' !== $args[0]) {
         WP_CLI::error(sprintf(__('%s is not a valid command.', 'jetpack'), $args[0]));
     }
     /*
      * Are they asking for all data?
      *
      * Loop through heartbeat data and organize by priority.
      */
     $all_data = isset($args[0]) && 'full' == $args[0] ? 'full' : false;
     if ($all_data) {
         WP_CLI::success(__('Jetpack is currently connected to WordPress.com', 'jetpack'));
         WP_CLI::line(sprintf(__("The Jetpack Version is %s", 'jetpack'), JETPACK__VERSION));
         WP_CLI::line(sprintf(__("The WordPress.com blog_id is %d", 'jetpack'), Jetpack_Options::get_option('id')));
         // Heartbeat data
         WP_CLI::line("\n" . __('Additional data: ', 'jetpack'));
         // Get the filtered heartbeat data.
         // Filtered so we can color/list by severity
         $stats = Jetpack::jetpack_check_heartbeat_data();
         // Display red flags first
         foreach ($stats['bad'] as $stat => $value) {
             printf("{$this->red_open}%-'.16s %s {$this->color_close}\n", $stat, $value);
         }
         // Display caution warnings next
         foreach ($stats['caution'] as $stat => $value) {
             printf("{$this->yellow_open}%-'.16s %s {$this->color_close}\n", $stat, $value);
         }
         // The rest of the results are good!
         foreach ($stats['good'] as $stat => $value) {
             // Modules should get special spacing for aestetics
             if (strpos($stat, 'odule-')) {
                 printf("%-'.30s %s\n", $stat, $value);
                 usleep(4000);
                 // For dramatic effect lolz
                 continue;
             }
             printf("%-'.16s %s\n", $stat, $value);
             usleep(4000);
             // For dramatic effect lolz
         }
     } else {
         // Just the basics
         WP_CLI::success(__('Jetpack is currently connected to WordPress.com', 'jetpack'));
         WP_CLI::line(sprintf(__('The Jetpack Version is %s', 'jetpack'), JETPACK__VERSION));
         WP_CLI::line(sprintf(__('The WordPress.com blog_id is %d', 'jetpack'), Jetpack_Options::get_option('id')));
         WP_CLI::line("\n" . _x("View full status with 'wp jetpack status full'", '"wp jetpack status full" is a command - do not translate', 'jetpack'));
     }
 }
Jetpack