=' ); if ( $overdue > 0 ) { $status = 'critical'; /* translators: %d: number of jobs. */ $label = sprintf( _n( '%d job overdue', '%d jobs overdue', $overdue, 'admin-powerups-for-woocommerce' ), $overdue ); $message = $cron_disabled ? __( 'Scheduled jobs are not running. WP-Cron is turned off on this site, so your host must run a server cron every minute.', 'admin-powerups-for-woocommerce' ) : __( 'Scheduled jobs are running late. This usually means the site gets few visits, or WP-Cron is blocked. Ask your host to run a server cron every minute.', 'admin-powerups-for-woocommerce' ); } elseif ( $cron_disabled ) { $status = 'recommended'; $label = __( 'WP-Cron off', 'admin-powerups-for-woocommerce' ); $message = __( 'WP-Cron is turned off. Jobs only run if your host runs a server cron. Nothing is late right now.', 'admin-powerups-for-woocommerce' ); } else { $status = 'good'; $label = __( 'Running', 'admin-powerups-for-woocommerce' ); $message = __( 'Scheduled jobs are running on time.', 'admin-powerups-for-woocommerce' ); } $result = array( 'status' => $status, 'label' => $label, 'message' => $message, 'overdue' => $overdue, 'failed' => $failed, 'pending' => $pending, 'cron_disabled' => $cron_disabled, ); /** * Filter the background job health result. * * @since 1.0.0 * @param array $result Result. */ self::$cache = (array) apply_filters( 'apwc_background_jobs_health', $result ); return self::$cache; } /** * Warning text for "wait" settings, or '' when jobs are healthy. * * @since 1.0.0 * @return string */ public static function wait_warning() { $jobs = SystemStatus::get()['jobs']; return 'good' === $jobs['status'] ? '' : $jobs['message']; } /** * Forget this request's result. * * @since 1.0.0 * @return void */ public static function flush() { self::$cache = null; } /** * Count our jobs in one query. * * @since 1.0.0 * @param string $status Action Scheduler status. * @param int|null $date Unix time to compare the scheduled date with. * @param string $compare Comparison operator. * @return int */ private static function count( $status, $date = null, $compare = '<=' ) { if ( ! class_exists( ActionScheduler::class ) || ! ActionScheduler::is_initialized() ) { return 0; } $query = array( 'group' => Jobs::GROUP, 'status' => $status, ); if ( null !== $date ) { $query['date'] = as_get_datetime_object( $date ); // The store expects a DateTime (UTC). $query['date_compare'] = $compare; } return (int) ActionScheduler::store()->query_actions( $query, 'count' ); } }