Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_pdf_filename() to API #1558

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,48 @@ public static function delete_pdf( $form_id, $pdf_id ) {
return $options->delete_pdf( $form_id, $pdf_id );
}

/**
* Retrieve the filename of the PDF document
* The .pdf extension is not returned by default (pass true to the 3rd param)
*
* See https://docs.gravitypdf.com/v6/developers/api/get_pdf_filename/ for more information about this method
*
* @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 $include_extension Whether to include the .pdf extension in the filename
*
* @return string|WP_Error Return the filename of the PDF, or a WP_Error on failure
*
* @return string|WP_Error
*
* @since 6.12
*/
public static function get_pdf_filename( $entry_id, $pdf_id, bool $include_extension ) {
$form_class = static::get_form_class();

/* Get our entry */
$entry = $form_class->get_entry( $entry_id );
if ( is_wp_error( $entry ) ) {
return new WP_Error( 'invalid_entry', esc_html__( 'Make sure to pass in a valid Gravity Forms Entry ID', 'gravity-forms-pdf-extended' ) );
}

/* Get our settings */
$setting = static::get_pdf( $entry['form_id'], $pdf_id );
if ( is_wp_error( $setting ) ) {
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' ) );
}

/** @var \GFPDF\Model\Model_PDF $pdf */
$pdf = static::get_mvc_class( 'Model_PDF' );

$filename = $pdf->get_pdf_name( $setting, $entry );
if ( $include_extension ) {
$filename .= '.pdf';
}

return $filename;
}

/**
* Retrieve an array of the global Gravity PDF settings (this doesn't include individual form configuration details - see GPDFAPI::get_form_pdfs)
*
Expand Down