Last active
April 16, 2020 16:10
-
-
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/ -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* caldera_forms_pdf_download_link_icon | |
* | |
* Controls the attributes set in the icon of the download link displayed after Form submissions | |
* | |
* @param $form Form configuration array | |
* | |
* @return array $attributes [ "src" , "alt", "width", "height", "style", "class"] attributes passed to the icon displayed in download link after submissions | |
*/ | |
add_filter("caldera_forms_pdf_download_link_icon", function( $attributes, $form ) { | |
//pass a different icon based on Form ID | |
if( $form['ID'] === "cf54894444877" ){ | |
$attributes["src"] = "path_to_my_icon.svg"; | |
} | |
return $attributes; | |
}, 10, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* caldera_forms_pdf_download_link_markup | |
* | |
* Controls the Dosnload link displayed after Forms Submissions | |
* | |
* @param string $markup html markup to be displayed | |
* @param string $href link built from Caldera_Forms_API_Util::url() | |
* @param array $img data for image attribute | |
* @param array $form Form configuration array | |
* @param array $transdata holds submission information | |
*/ | |
add_filter("caldera_forms_pdf_download_link_markup", function( $markup, $href, $img, $form, $transdata ) { | |
//pass a different link based on Form ID | |
if( $form['ID'] === "cf54894444877" ){ | |
$markup = '<br /><div> | |
<a href=' . $href . ' target="_blank" class="cf-pdf-download-link">' . __('Download', 'cf_pdf') . ' | |
<img src="' . $img['src'] . '" alt="' . $img['alt'] . '" class="' . $img['class'] . '" width="' . $img['width'] . '" height="' . $img['height'] . '" style="' . $img['style'] . '" /> | |
</a></div>'; | |
} | |
return $markup; | |
}, 10, 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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