Skip to content

Instantly share code, notes, and snippets.

@New0
Last active April 16, 2020 16:10
Show Gist options
  • Save New0/745133d102fe05110d1429603e9177bb to your computer and use it in GitHub Desktop.
Save New0/745133d102fe05110d1429603e9177bb to your computer and use it in GitHub Desktop.
Caldera Forms PDF Submissions hooks examples - https://calderaforms.com/doc/pdf-submissions-hooks/ -
<?php
/**
* caldera_forms_api_allow_pdf_download
*
* Control how it is allowed to download the PDF files
*
* @param boolean $allowed
* @param array $request
*/
add_filter("caldera_forms_api_allow_pdf_download", function($allowed, $request ) {
//Create a custom function that return true or false based on your needs
$allowed = my_custom_function();
return $allowed;
}, 10, 2);
<?php
/**
* caldera_forms_pdf_attachment_filename
*
* NOTE: Editing the filename will store the file on the server. Work will be required to delete them.
*
* @param string|null $entry_id Entry ID or null
* @param string|null $form_id Form ID or null
*/
add_filter("caldera_forms_pdf_attachment_filename", function($filename, $entry_id, $form_id) {
//Set a different filename for a precise Form
//EDIT FORM ID
if($form_id = "cf1487563"){
$filename = "this_precise_form_filename";
}
return $filename;
}, 10, 3);
<?php
/**
* caldera_forms_pdf_content
*
* Controls the content displayed by the PDF
*
* @param string $entry_id Entry ID
* @param string $form_id Form ID
*
* @return string $content of html
*/
add_filter("caldera_forms_pdf_content", function( $content, $entry_id, $form_id ) {
//$entry ID can be used to get data of current entry being converted to PDF like :
$entry = Caldera_Forms::get_entry($entry_id, $form_id);
//Or we can pass custom data based on Form ID
if( $form_id === "cf54894444877" ){
$content .= "<div><p>My extra Footer content</p></div>";
}
return $content;
}, 10, 3);
<?php
/**
* caldera_forms_pdf_download_filename
*
* Controls the Filename of PDF being downloads by default $filename = $form_id . "-" . $entry_id . ".pdf"
*
* @param string $entry_id Entry ID
* @param string $form_id Form ID
*
* @return string $filename that will be used for the PDF downloads of an entry ending with .pdf
*/
add_filter("caldera_forms_pdf_download_filename", function( $filename, $entry_id, $form_id ) {
//pass filename based on Form ID
if( $form_id === "cf54894444877" ){
$filename = "my_custom_name.pdf";
}
return $filename;
}, 10, 3);
<?php
/**
* caldera_forms_pdf_upload_dir
*
* NOTE: Editing the filename will store the file on the server. Work will be required to delete them.
*
* @param array $upload_dir value returned by wp_upload_dir();
* @param string|null $entry_id Entry ID or null
* @param string|null $form_id Form ID or null
*/
add_filter("caldera_forms_pdf_upload_dir", function($pdf_upload_dir, $upload_dir, $entry_id, $form_id) {
//EDIT FORM ID
if($form_id = "cf1487563"){
$pdf_upload_dir = $upload_dir . "/my_special_folder_in_wp-content_uploads/and_subfolder";
}
return $pdf_upload_dir;
}, 10, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment