/**
  * checks for error logs posts for lift and uses intervals with count
  * thresholds. returns the overall stoplight color and an array of data
  * for the error count, threshold, and light color if met.
  *
  * @global int $lift_health_interval
  * @static
  * @return array
  */
 public static function get_local_status()
 {
     if (!Lift_Search::error_logging_enabled()) {
         return array('severity' => 0, 'reason' => '', 'errors' => false, 'status' => 0);
     }
     $intervals = array(60 * 60 => array('severity' => 2, 'threshold' => 5), 60 * 30 => array('severity' => 1, 'threshold' => 2));
     $intervals = apply_filters('lift_search_health_checkup_intervals', $intervals);
     $severity = 0;
     $reason = '';
     $errors = false;
     foreach ($intervals as $interval => $data) {
         global $lift_health_interval;
         $lift_health_interval = $interval;
         add_filter('posts_where', array(__CLASS__, 'filter_posts_where'));
         $q = new WP_Query(array('posts_per_page' => 1, 'post_type' => Voce_Error_Logging::POST_TYPE, 'tax_query' => array(array('taxonomy' => Voce_Error_Logging::TAXONOMY, 'field' => 'slug', 'terms' => array('error', 'lift-search'), 'operator' => 'AND'))));
         remove_filter('posts_where', array(__CLASS__, 'filter_posts_where'));
         $post_count = $q->found_posts;
         if ($post_count >= $data['threshold']) {
             $errors = true;
             $severity = $data['severity'];
             $reason = sprintf('%d or more errors in the last %s', $data['threshold'], human_time_diff(time() - $interval));
         }
         $error_counts[] = array('threshold' => $data['threshold'], 'count' => $post_count, 'interval' => $interval, 'severity' => $severity);
     }
     $results = array('errors' => $errors, 'severity' => $severity, 'reason' => $reason, 'status' => $error_counts);
     return $results;
 }
 public function action__wp_ajax_lift_error_log()
 {
     $response = (object) array('error' => false, 'nonce' => wp_create_nonce('lift_error_log'));
     if (Lift_Search::error_logging_enabled()) {
         $response->view_all_url = esc_url(admin_url(sprintf('edit.php?post_type=%s', Voce_Error_Logging::POST_TYPE)));
         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
             check_ajax_referer('lift_error_log', 'nonce');
             $response = Voce_Error_Logging::delete_logs(array('lift-search'));
         } else {
             $args = array('post_type' => Voce_Error_Logging::POST_TYPE, 'posts_per_page' => 5, 'post_status' => 'any', 'orderby' => 'date', 'order' => 'DESC', 'tax_query' => array(array('taxonomy' => Voce_Error_Logging::TAXONOMY, 'field' => 'slug', 'terms' => array('error', 'lift-search'), 'operator' => 'AND')));
             $query = new WP_Query($args);
             $response->current_page = $query->get('paged');
             $response->per_page = $query->get('posts_per_page');
             $response->found_rows = $query->found_posts;
             $response->errors = array();
             foreach ($query->posts as $post) {
                 $response->errors[] = array('error_html' => sprintf('<strong>%s</strong><pre>%s</pre>', esc_html($post->post_title), wpautop($post->post_content)), 'date' => mysql2date('D. M d Y g:ia', $post->post_date));
             }
         }
     } else {
         status_header(400);
         $response->view_all_url = '';
         $response->error = array('code' => 'logging_disabled', 'Error Logging is Disabled');
     }
     header('Content-Type: application/json');
     die(json_encode($response));
 }