Filter
uncanny-automator-pro
learndash_pdf_subject
Filters the subject of the pdf. Filters the subject of the PDF certificate before it is generated and sent.
add_filter( 'learndash_pdf_subject', $callback, 10, 1 );
Description
Filter the subject line of a LearnDash PDF certificate. This hook provides access to the `$pdf_subject` string, the `TCPDF` object, and the certificate's post ID. Developers can modify the subject to customize it based on specific certificate or user data.
Usage
add_filter( 'learndash_pdf_subject', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Modifies the PDF subject for LearnDash certificates.
*
* This function intercepts the default PDF subject generated by LearnDash
* and appends the course title to it, providing more context within the PDF metadata.
*
* @param string $pdf_subject The original PDF subject.
* @param TCPDF $pdf The TCPDF instance.
* @param int $cert_id The ID of the certificate post.
* @return string The modified PDF subject.
*/
add_filter( 'learndash_pdf_subject', function( $pdf_subject, $pdf, $cert_id ) {
// Get the course ID associated with this certificate.
// This assumes a relationship where a certificate is tied to a specific course.
// The actual method to retrieve the course ID might vary based on your setup
// or other plugins you might be using. For this example, we'll assume a
// meta key like '_ld_certificate_course_id' exists or can be retrieved.
$course_id = get_post_meta( $cert_id, '_ld_certificate_course_id', true );
if ( $course_id ) {
// Get the course title.
$course_title = get_the_title( $course_id );
// Append the course title to the existing subject.
$pdf_subject .= ' - ' . $course_title;
}
// Return the modified subject.
return $pdf_subject;
}, 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:1017
/**
* Filters the subject of the pdf.
*
* @param string $pdf_subject PDF subject
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $cert_id Certificate post ID.
*/
$pdf->SetSubject( apply_filters( 'learndash_pdf_subject', strip_tags( get_the_category_list( ',', '', $cert_args['cert_id'] ) ), $pdf, $cert_args['cert_id'] ) );
/**
* Filters the pdf keywords.
*
* @param string $pdf_keywords PDF keywords.
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $cert_id Certificate post ID.