PDF for GravityView Hooks – gfpdf_gv_revoke_pdfs_for_unpublished_view
Description
Keep serving a View's PDFs after it's unpublished or trashed.
When a View is trashed, or changed from Published to Draft, Pending, Scheduled or Private, its PDFs stop being served. Existing PDF links, including links already sent by email, show "The PDF is no longer accessible." and the Share PDF form stops sending. This matches how GravityView treats the View itself.
Logged-in users with GravityView's read_gravityview capability can still open PDFs for a Draft, Pending, Scheduled or Private View, so you can check it before publishing. A trashed View's PDFs aren't served to anyone.
Return false to keep serving a View's PDFs while it's unpublished, or check $status to allow some statuses and not others. You don't need this filter to restore links after republishing a View or restoring it from the trash. Links aren't invalidated, only refused while the View is unavailable.
This check doesn't apply to PDFs generated with the PDFGV_API or attached to form notifications.
If you return false, anyone with a PDF link can keep downloading that View's PDFs after it's unpublished, for as long as the link is valid. Limit the change to the Views and statuses that need it.
Version
This hook was introduced in PDF for GravityView 2.0.
Arguments
The following arguments are passed to functions that use this hook:
$revoke | bool
- Return
trueto stop serving the View's PDFs while it's unpublished or trashed, orfalseto keep serving them. - The default value is
true.
$view | \GV\View
- The View the PDF was requested for.
$status | string | false
- The View's post status, such as
publish,draft,pending,future,privateortrash. falseif the status can't be read.
Usage
Keep serving PDFs for Private Views, but still stop them when a View is trashed or set back to Draft:
add_filter( 'gfpdf_gv_revoke_pdfs_for_unpublished_view', function( $revoke, $view, $status ) {
if ( $status === 'private' ) {
return false;
}
return $revoke;
}, 10, 3 );
Keep serving View 885's PDFs whatever its status:
add_filter( 'gfpdf_gv_revoke_pdfs_for_unpublished_view', function( $revoke, $view, $status ) {
if ( (int) $view->ID === 885 ) {
return false;
}
return $revoke;
}, 10, 3 );
See Troubleshooting if a PDF link has stopped working.
Source Code
This filter is located in src/Pdf/Access/ViewStatus.php of the PDF for GravityView extension.