store = $store; } /** * {@inheritDoc} */ public function group(): string { return 'errors'; } /** * {@inheritDoc} */ public function run(): array { $now = time(); $day = $this->total( $this->store->since( $now - DAY_IN_SECONDS ) ); $week = $this->total( $this->store->since( $now - WEEK_IN_SECONDS ) ); $url = admin_url( 'tools.php?page=keepwatch#errors' ); if ( $day > 0 ) { return array( new Result( 'errors.fatal', Result::CRITICAL, /* translators: %d: number of fatal errors */ sprintf( _n( '%d PHP fatal error in the last 24 hours', '%d PHP fatal errors in the last 24 hours', $day, 'keepwatch' ), $day ), __( 'A fatal error stops the page from loading for the visitor who triggered it. Check the error list below to see which plugin or theme caused it.', 'keepwatch' ), $url, __( 'View errors', 'keepwatch' ) ), ); } if ( $week > 0 ) { return array( new Result( 'errors.fatal', Result::RECOMMENDED, /* translators: %d: number of fatal errors */ sprintf( _n( '%d PHP fatal error in the last 7 days', '%d PHP fatal errors in the last 7 days', $week, 'keepwatch' ), $week ), __( 'No new fatal errors in the last 24 hours. Review the list to make sure the cause has been fixed.', 'keepwatch' ), $url, __( 'View errors', 'keepwatch' ) ), ); } return array( new Result( 'errors.fatal', Result::GOOD, __( 'No PHP fatal errors in the last 7 days', 'keepwatch' ) ), ); } /** * Sum occurrences. * * @param array $errors Errors. */ private function total( array $errors ): int { $total = 0; foreach ( $errors as $error ) { $total += (int) $error['count']; } return $total; } }