false, 'count' => 0, 'max' => $max, 'retry_after' => 0, ); } // The key carries the window slice, so each window gets its own // counter and expires on its own. Re-arming a single transient's TTL // on every request would instead extend the block indefinitely. $now = time(); $slice = (int) floor( $now / $window ); $retry_after = ( ( $slice + 1 ) * $window ) - $now; $bucket = self::is_write_method( $method ) ? 'w' : 'r'; $key = self::PREFIX . $bucket . '_' . self::identity() . '_' . $slice; $count = (int) get_transient( $key ) + 1; set_transient( $key, $count, $window ); return array( 'limited' => $count > $max, 'count' => $count, 'max' => $max, 'retry_after' => max( 1, $retry_after ), ); } }