Filter
uncanny-automator-pro
learndash_pdf_username
Filters username of the user to be used in creating certificate PDF. Filters the username displayed on a LearnDash certificate PDF before it's generated.
add_filter( 'learndash_pdf_username', $callback, 10, 3 );
Description
This filter hook, `learndash_pdf_username`, allows modification of the user's display name before it's embedded into a LearnDash certificate PDF. It fires during PDF generation. Developers can alter the displayed username for personalization or privacy, using the user's ID and certificate ID for context.
Usage
add_filter( 'learndash_pdf_username', 'your_function_name', 10, 3 );
Parameters
-
$user_name(string) - User display name.
-
$user_id(int) - User ID.
-
$cert_id(int) - Certificate post ID.
Return Value
The filtered value.
Examples
// Example: Append a prefix to the username in the PDF title if it's for a specific certificate.
add_filter( 'learndash_pdf_username', 'my_custom_learndash_pdf_username', 10, 3 );
/**
* Custom function to modify the username for LearnDash certificate PDFs.
*
* This example appends a prefix to the username if the certificate ID is a specific one (e.g., 123).
*
* @param string $user_name The original user display name.
* @param int $user_id The ID of the user.
* @param int $cert_id The post ID of the certificate.
* @return string The modified username.
*/
function my_custom_learndash_pdf_username( $user_name, $user_id, $cert_id ) {
// Check if this is a specific certificate we want to modify the username for.
// Replace 123 with the actual certificate ID you want to target.
if ( $cert_id === 123 ) {
// Prepend a custom string to the username.
return 'Certified User: ' . $user_name;
}
// Return the original username if it's not for the targeted certificate.
return $user_name;
}
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:720
/**
* Filters username of the user to be used in creating certificate PDF.
*
* @param string $user_name User display name.
* @param int $user_id User ID.
* @param int $cert_id Certificate post ID.
*/
$learndash_pdf_username = apply_filters( 'learndash_pdf_username', $cert_args['user']->display_name, $cert_args['user_id'], $cert_args['cert_id'] );
if ( ! empty( $learndash_pdf_username ) ) {
if ( ! empty( $cert_args['pdf_title'] ) ) {
$cert_args['pdf_title'] .= " $sep ";
}
$cert_args['pdf_title'] .= $learndash_pdf_username;
}