Make WordPress Core

Ticket #47223: 47223.2.diff

File 47223.2.diff, 2.9 KB (added by peterwilsoncc, 6 years ago)
  • src/wp-admin/includes/class-wp-site-health.php

    diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php
    index 12e1273..d1a7d22 100644
    a b class WP_Site_Health { 
    14111411                                )
    14121412                        );
    14131413                } else {
    1414                         if ( $this->has_missed_cron() ) {
     1414                        $has_missed_cron = $this->has_missed_cron();
     1415                        if ( 'failed' === $has_missed_cron ) {
    14151416                                $result['status'] = 'recommended';
    14161417
    14171418                                $result['label'] = __( 'A scheduled event has failed' );
    class WP_Site_Health { 
    14241425                                                $this->last_missed_cron
    14251426                                        )
    14261427                                );
     1428                        } elseif ( 'late' === $has_missed_cron ) {
     1429                                $result['status'] = 'recommended';
     1430
     1431                                $result['label'] = __( 'A scheduled event is late' );
     1432
     1433                                $result['description'] = sprintf(
     1434                                        '<p>%s</p>',
     1435                                        sprintf(
     1436                                                /* translators: %s: The name of the failed cron event. */
     1437                                                __( 'The scheduled event, %s, is late to run. Your site still works, but this may indicate that scheduling posts or automated updates may not work as intended.' ),
     1438                                                $this->last_missed_cron
     1439                                        )
     1440                                );
    14271441                        }
    14281442                }
    14291443
    class WP_Site_Health { 
    19071921        /**
    19081922         * Check if any scheduled tasks have been missed.
    19091923         *
    1910          * Returns a boolean value of `true` if a scheduled task has been missed and ends processing. If the list of
    1911          * crons is an instance of WP_Error, return the instance instead of a boolean value.
     1924         * Returns a boolean `false` if there are no missed cron jobs, otherwise
     1925         * returns the status of missed events as either `late` or `failed`.
     1926         *
     1927         * If getting cron jobs has failed, a WP_Error object is returned.
    19121928         *
    19131929         * @since 5.2.0
    19141930         *
    1915          * @return bool|WP_Error true if a cron was missed, false if it wasn't. WP_Error if the cron is set to that.
     1931         * @return bool|string|WP_Error False if no cron was missed,
     1932         *                              'failed' if a cron failed to run,
     1933         *                              'late' if a cron is late to run.
     1934         *                              WP_Error if the cron is set to that.
    19161935         */
    19171936        public function has_missed_cron() {
    19181937                if ( is_wp_error( $this->crons ) ) {
    19191938                        return $this->crons;
    19201939                }
    19211940
     1941                $late_timeout   = 0;
     1942                $failed_timeout = -5 * MINUTE_IN_SECONDS;
     1943                $late_cron      = false;
     1944
     1945                if ( defined( 'DISABLE_WP_CRON' ) && true === DISABLE_WP_CRON ) {
     1946                        $late_timeout   = -15 * MINUTE_IN_SECONDS;
     1947                        $failed_timeout = -1 * HOUR_IN_SECONDS;
     1948                }
     1949
    19221950                foreach ( $this->crons as $id => $cron ) {
    1923                         if ( ( $cron->time - time() ) < 0 ) {
     1951                        if ( ( $cron->time - time() ) < $failed_timeout ) {
     1952                                $this->last_missed_cron = $cron->hook;
     1953                                return 'failed';
     1954                        } elseif ( ( $cron->time - time() < $late_timeout ) ) {
    19241955                                $this->last_missed_cron = $cron->hook;
    1925                                 return true;
     1956                                $late_cron              = true;
    19261957                        }
    19271958                }
    19281959
     1960                if ( true === $late_cron ) {
     1961                        return 'late';
     1962                }
     1963
    19291964                return false;
    19301965        }
    19311966