Make WordPress Core

Ticket #47223: 47223.diff

File 47223.diff, 2.2 KB (added by rockfire, 6 years ago)
  • wp-admin/includes/class-wp-site-health.php

     
    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' );
     
    14251426                                        )
    14261427                                );
    14271428                        }
     1429                        else if ( 'late' === $has_missed_cron ) {
     1430                                $result['status'] = 'recommended';
     1431
     1432                                $result['label'] = __( 'A scheduled event is late' );
     1433
     1434                                $result['description'] = sprintf(
     1435                                        '<p>%s</p>',
     1436                                        sprintf(
     1437                                                /* translators: %s: The name of the failed cron event. */
     1438                                                __( '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.' ),
     1439                                                $this->last_missed_cron
     1440                                        )
     1441                                );
     1442                        }
    14281443                }
    14291444
    14301445                return $result;
     
    19121927         *
    19131928         * @since 5.2.0
    19141929         *
    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.
     1930         * @return bool|string|WP_Error false if no cron was missed, 'failed' if a cron failed to run, 'late' if a cron is late to run. WP_Error if the cron is set to that.
    19161931         */
    19171932        public function has_missed_cron() {
    19181933                if ( is_wp_error( $this->crons ) ) {
    19191934                        return $this->crons;
    19201935                }
    19211936
     1937                $late_timeout = 0;
     1938                $failed_timeout = -5 * MINUTE_IN_SECONDS;
     1939                $late_cron = false;
     1940
     1941                if ( defined( 'DISABLE_WP_CRON' )  && true === DISABLE_WP_CRON ) {
     1942                        $late_timeout = -15 * MINUTE_IN_SECONDS;
     1943                        $failed_timeout = -HOUR_IN_SECONDS;
     1944                }
     1945
    19221946                foreach ( $this->crons as $id => $cron ) {
    1923                         if ( ( $cron->time - time() ) < 0 ) {
     1947                        if ( ( $cron->time - time() ) < $failed_timeout ) {
    19241948                                $this->last_missed_cron = $cron->hook;
    1925                                 return true;
     1949                                return 'failed';
    19261950                        }
     1951                        else if ( ( $cron->time - time() < $late_timeout ) ) {
     1952                                $this->last_missed_cron = $cron->hook;
     1953                                $late_cron = true;
     1954                        }
     1955                }
     1956
     1957                if ( true === $late_cron ) {
     1958                        return 'late';
    19271959                }
    19281960
    19291961                return false;