run(); if ( ! LabClient::enabled() || ! self::take_daily_slot() ) { return; } $urls = LabClient::urls(); $runs = count( $urls ) > self::FULL_RUN_MAX_URLS ? 1 : 0; // 0 = the client's default. $when = time(); foreach ( $urls as $url ) { Cron::schedule_single( $when, LabClient::URL_HOOK, array( $url, $event_ids, $runs ) ); $when += self::STAGGER_SECONDS; } } /** * Count this check against the daily cap. A site that changes all day is * still covered by the daily lab check, so going over the cap only drops * the extra re-tests. */ private function take_daily_slot(): bool { /** * Filter how many change-triggered lab checks may run per day. * * @param int $max Checks per GMT day. */ $max = max( 0, (int) apply_filters( 'aftercare_lab_change_checks_per_day', 4 ) ); $today = gmdate( 'Y-m-d' ); $count = get_option( self::COUNT_OPT, array() ); $used = is_array( $count ) && ( $count['day'] ?? '' ) === $today ? (int) ( $count['count'] ?? 0 ) : 0; if ( $used >= $max ) { return false; } update_option( self::COUNT_OPT, array( 'day' => $today, 'count' => $used + 1, ), false ); return true; } }