Skip to content

Commit

Permalink
Add temporary PDF cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejackson1 committed Jul 31, 2024
1 parent b8a1326 commit f31eca4
Show file tree
Hide file tree
Showing 23 changed files with 1,159 additions and 554 deletions.
33 changes: 19 additions & 14 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,21 @@ public static function delete_plugin_option( $key ) {
}

/**
* When provided the Gravity Form entry ID and PDF ID, this method will correctly generate the PDF, save it to disk,
* trigger appropriate actions and return the absolute path to the PDF.
* Generate a PDF, save it to disk, and return the absolute path to the document
*
* See https://docs.gravitypdf.com/v6/developers/api/create_pdf/ for more information about this method
*
* @param integer $entry_id The Gravity Form entry ID
* @param string $pdf_id The Gravity PDF ID number (the pid number in the URL when viewing a setting in the admin area)
* @param int $entry_id The Gravity Form entry ID
* @param string $pdf_id The Gravity PDF ID number (the pid number in the URL when viewing a setting in the admin area)
* @param bool $bypass_cache Force a new PDF to be generated
*
* @return mixed Return the full path to the PDF, or a WP_Error on failure
* @return string|WP_Error Return the full path to the PDF, or a WP_Error on failure
*
* @since 4.0
* @since 6.12 All PDFs are cached on disk for ~1 hour, but are auto-purged if the form, entry, or PDF settings change
* Re-running the method will return the cached PDF if it exists, unless $bypass_cache = true
*/
public static function create_pdf( $entry_id, $pdf_id ) {
public static function create_pdf( $entry_id, $pdf_id, $bypass_cache = false ) {

$form_class = static::get_form_class();

Expand All @@ -478,16 +480,19 @@ public static function create_pdf( $entry_id, $pdf_id ) {
return new WP_Error( 'invalid_pdf_setting', esc_html__( 'Could not located the PDF Settings. Ensure you pass in a valid PDF ID.', 'gravity-forms-pdf-extended' ) );
}

$pdf = static::get_mvc_class( 'Model_PDF' );
$form = $form_class->get_form( $entry['form_id'] );
if ( $bypass_cache ) {
add_filter( 'gfpdf_override_pdf_bypass', '__return_true', 9999 );
}

/** @var \GFPDF\Model\Model_PDF $pdf */
$pdf = static::get_mvc_class( 'Model_PDF' );
$path_to_pdf = $pdf->generate_and_save_pdf( $entry, $setting );

add_filter( 'gfpdf_override_pdf_bypass', '__return_true' );
do_action( 'gfpdf_pre_generate_and_save_pdf', $form, $entry, $setting );
$filename = $pdf->generate_and_save_pdf( $entry, $setting );
do_action( 'gfpdf_post_generate_and_save_pdf', $form, $entry, $setting );
remove_filter( 'gfpdf_override_pdf_bypass', '__return_true' );
if ( $bypass_cache ) {
remove_filter( 'gfpdf_override_pdf_bypass', '__return_true', 9999 );
}

return $filename;
return $path_to_pdf;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions pdf.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Gravity PDF
Version: 6.11.1
Version: 6.12.0
Description: Automatically generate highly customizable PDF documents using Gravity Forms.
Author: Blue Liquid Designs
Author URI: https://blueliquiddesigns.com.au
Expand All @@ -28,7 +28,7 @@
/*
* Set base constants we'll use throughout the plugin
*/
define( 'PDF_EXTENDED_VERSION', '6.11.1' ); /* the current plugin version */
define( 'PDF_EXTENDED_VERSION', '6.12.0' ); /* the current plugin version */
define( 'PDF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); /* plugin directory path */
define( 'PDF_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); /* plugin directory url */
define( 'PDF_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); /* the plugin basename */
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/Controller_Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public function check_install_status() {
* Determine if we should be saving the PDF settings
*
* @since 4.0
*
* @deprecated 6.0
*/
public function maybe_uninstall() {
_doing_it_wrong( __METHOD__, 'This method has been moved to Controller_Uninstall::uninstall_addon()', '6.0' );
Expand Down
Loading

0 comments on commit f31eca4

Please sign in to comment.