1, 'reset' => $now + $window_seconds, ); set_transient( $tkey, $data, $window_seconds ); return true; } $reset = (int) $data['reset']; $count = (int) $data['count']; if ( $now >= $reset ) { // New window. $data = array( 'count' => 1, 'reset' => $now + $window_seconds, ); set_transient( $tkey, $data, $window_seconds ); return true; } if ( $count >= $limit ) { return false; } $data['count'] = $count + 1; // Keep existing reset window; transient TTL should not extend beyond reset. $ttl = max( 1, $reset - $now ); set_transient( $tkey, $data, $ttl ); return true; } }