Action
Since 2.4.7
uncanny-automator-pro
learndash_certification_created
Fires after creating certificate `TCPDF` class object. Fires after a LearnDash certificate is created, providing access to the PDF object and certificate ID.
add_action( 'learndash_certification_created', $callback, 10, 1 );
Description
Fires immediately after a LearnDash certificate's TCPDF object is created. Developers can use this action to access and modify the TCPDF instance or certificate ID before the PDF is finalized, enabling custom PDF manipulations or data integration.
Usage
add_action( 'learndash_certification_created', 'your_function_name', 10, 1 );
Examples
add_action( 'learndash_certification_created', 'my_learndash_certification_pdf_hook', 10, 2 );
/**
* Example callback function for the learndash_certification_created action hook.
* This function demonstrates how to interact with the generated TCPDF object
* and the certificate ID to potentially add custom elements or metadata.
*
* @param TCPDF $pdf The TCPDF class instance.
* @param int $cert_id The certificate post ID.
*/
function my_learndash_certification_pdf_hook( TCPDF $pdf, int $cert_id ) {
// Add a custom watermark to the PDF certificate.
// This is just an example; the actual watermark text and positioning
// would likely be more complex and depend on your specific needs.
$watermark_text = 'CONFIDENTIAL - Cert ID: ' . $cert_id;
$pdf->SetAlpha(0.3); // Make watermark semi-transparent
$pdf->SetFont('helvetica', 'B', 50);
$pdf->SetTextColor(200, 200, 200);
$pdf->RotatedText(100, 150, $watermark_text, 45);
$pdf->SetAlpha(1); // Reset alpha to default
// You could also fetch certificate-specific data using $cert_id
// and add it to the PDF, or log the creation event.
error_log( sprintf( 'LeafDash certification PDF created for Certificate ID: %d', $cert_id ) );
// If this were a filter hook that modified the $pdf object or returned a value,
// you would ensure a return statement is present. For an action hook that
// modifies an object passed by reference, direct manipulation is sufficient.
}
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:979
* Fires after creating certificate `TCPDF` class object.
*
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $cert_id Certificate post ID.
*
* @since 2.4.7
*/
do_action( 'learndash_certification_created', $pdf, $cert_args['cert_id'] );
// Set document information
/**
* Filters the value of pdf creator.
*
* @param string $pdf_creator The name of the PDF creator.