learndash_pdf_creator
Filters the value of pdf creator. Filters the PDF creator's name before it's set for a LearnDash certificate.
add_filter( 'learndash_pdf_creator', $callback, 10, 1 );
Description
Allows modification of the PDF creator name used in certificate generation. Developers can dynamically change who is listed as the creator of the PDF document, providing the `TCPDF` instance and certificate ID for context.
Usage
add_filter( 'learndash_pdf_creator', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Change the PDF creator name to include the site URL.
*
* This function modifies the PDF creator string to append the WordPress site URL
* to the default creator name. This can be useful for identifying the origin
* of generated PDFs.
*
* @param string $pdf_creator The original PDF creator name.
* @param TCPDF $pdf The TCPDF class instance.
* @param int $cert_id The certificate post ID.
* @return string The modified PDF creator name.
*/
function my_learndash_custom_pdf_creator( $pdf_creator, $pdf, $cert_id ) {
// Get the site URL.
$site_url = get_bloginfo( 'url' );
// Append the site URL to the existing creator name.
// Ensure we don't duplicate if the site URL is somehow already present.
if ( strpos( $pdf_creator, $site_url ) === false ) {
$pdf_creator .= ' - ' . $site_url;
}
// Return the modified creator name.
return $pdf_creator;
}
add_filter( 'learndash_pdf_creator', 'my_learndash_custom_pdf_creator', 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
src/includes/tcpdf-certificate-code.php:553
/**
* Filters the value of pdf creator.
*
* @param string $pdf_creator The name of the PDF creator.
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $cert_id Certificate post ID.
*/
$pdf->SetCreator( apply_filters( 'learndash_pdf_creator', PDF_CREATOR, $pdf, $cert_args['cert_id'] ) );
/**
* Filters the name of the pdf author.
*
* @param string $pdf_author_name PDF author name.
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $cert_id Certificate post ID.