PDF for GravityView Hooks – gfpdf_gv_render_budget
Description
Raise, lower or turn off the render budget: how much PDF generation each visitor can do per window (five minutes by default). Once the budget is spent, further PDF requests are refused until the next window. Rate limiting explains who's counted and who's exempt.
The budget is counted in units. A Single Entry PDF costs 11 units, and a Multiple Entries PDF costs 10 plus 1 per entry. An embedded View field adds 5 units per entry it's shown for. A PDF served from the cache costs the same as a fresh one. The defaults allow about 100 Single Entry PDFs, or about 20 Multiple Entries PDFs of 100 entries, per visitor per window. Single Entry and Multiple Entries PDFs have separate budgets.
A visitor over budget gets an HTTP 429 Too Many Requests page ("There have been too many PDF requests from this connection") with a Retry-After header. A Share PDF form submitted over budget isn't sent, and the sender is told when to try again. Share PDF emails also have their own sending limits.
Set the window length with gfpdf_gv_render_budget_window.
Version
This hook was introduced in PDF for GravityView 2.0.
Arguments
The following arguments are passed to functions that use this hook:
$max | int
- The budget per visitor per window, in units.
- A value below
1turns the budget off. - For logged-in users, the value is then multiplied by gfpdf_gv_render_budget_logged_in_multiplier.
- The default value is
1100for Single Entry PDFs and2500for Multiple Entries PDFs.
$context | string
- Which PDF type the budget is for.
- Valid values include:
singledirectory(Multiple Entries PDF)
$logged_in | bool
- Whether the visitor is logged in.
Usage
Double the Multiple Entries PDF budget, for sites where these PDFs often hold hundreds of entries:
add_filter( 'gfpdf_gv_render_budget', function( $max, $context, $logged_in ) {
return $context === 'directory' ? $max * 2 : $max;
}, 10, 3 );
Halve the Single Entry PDF budget for logged-out visitors only:
add_filter( 'gfpdf_gv_render_budget', function( $max, $context, $logged_in ) {
if ( $context === 'single' && ! $logged_in ) {
return (int) ( $max / 2 );
}
return $max;
}, 10, 3 );
To lift the limit for staff, give their role a capability listed in gfpdf_gv_render_budget_exempt_caps instead of turning the budget off for every logged-in user.
Source Code
This filter is located in src/Pdf/Access/RenderBudget.php of the PDF for GravityView extension.