Summery Summery
Run our scheduled event to check and update the latest site health status for the website.
Syntax Syntax
Source Source
File: wp-admin/includes/class-wp-site-health.php
* @return string The modified body class string.
*/
public function admin_body_class( $body_class ) {
$screen = get_current_screen();
if ( 'site-health' !== $screen->id ) {
return $body_class;
}
$body_class .= ' site-health';
return $body_class;
}
/**
* Initiate the WP_Cron schedule test cases.
*
* @since 5.2.0
*/
private function wp_schedule_test_init() {
$this->schedules = wp_get_schedules();
$this->get_cron_tasks();
}
/**
* Populate our list of cron events and store them to a class-wide variable.
*
* @since 5.2.0
*/
private function get_cron_tasks() {
$cron_tasks = _get_cron_array();
if ( empty( $cron_tasks ) ) {
$this->crons = new WP_Error( 'no_tasks', __( 'No scheduled events exist on this site.' ) );
return;
}
$this->crons = array();
foreach ( $cron_tasks as $time => $cron ) {
foreach ( $cron as $hook => $dings ) {
foreach ( $dings as $sig => $data ) {
$this->crons[ "$hook-$sig-$time" ] = (object) array(
'hook' => $hook,
'time' => $time,
'sig' => $sig,
'args' => $data['args'],
'schedule' => $data['schedule'],
'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
);
}
}
}
}
/**
* Check if any scheduled tasks have been missed.
*
* Returns a boolean value of `true` if a scheduled task has been missed and ends processing.
*
* If the list of crons is an instance of WP_Error, returns the instance instead of a boolean value.
*
* @since 5.2.0
*
* @return bool|WP_Error True if a cron was missed, false if not. WP_Error if the cron is set to that.
*/
public function has_missed_cron() {
if ( is_wp_error( $this->crons ) ) {
return $this->crons;
}
foreach ( $this->crons as $id => $cron ) {
if ( ( $cron->time - time() ) < $this->timeout_missed_cron ) {
$this->last_missed_cron = $cron->hook;
return true;
}
}
return false;
}
/**
* Check if any scheduled tasks are late.
Advertisement
Changelog Changelog
| Version | Description |
|---|---|
| 5.4.0 | Introduced. |