ucec_generate_course_certificate_content
function modify_pdf_certificate_content( $content, $user_id, $course_id ){ //enter your modifications or use regex to modify content return $content; } add_action( 'ucec_generate_course_certificate_content', 'modify_pdf_certificate_content', 20, 3 ); Filters the content of a course certificate just before it's generated for a user.
add_filter( 'ucec_generate_course_certificate_content', $callback, 10, 2 );
Description
Filters the content used to generate a course certificate. Developers can modify the certificate's text, including course information and user metadata, before it's rendered as a PDF. This hook provides the certificate content, user object, and generation parameters, allowing for dynamic customization.
Usage
add_filter( 'ucec_generate_course_certificate_content', 'your_function_name', 10, 2 );
Parameters
-
$cert_content(mixed) - - **$user** `mixed`
-
$parameters(mixed)
Return Value
The filtered value.
Examples
add_filter( 'ucec_generate_course_certificate_content', 'my_custom_certificate_content', 10, 3 );
/**
* Modifies the certificate content for a specific course to include a personalized message.
*
* @param string $cert_content The original certificate content.
* @param int $user_id The ID of the user for whom the certificate is generated.
* @param int $course_id The ID of the course the user completed.
* @return string The modified certificate content.
*/
function my_custom_certificate_content( $cert_content, $user_id, $course_id ) {
// Only apply this modification to a specific course, e.g., course ID 123.
if ( $course_id == 123 ) {
$user = get_user_by( 'id', $user_id );
if ( $user ) {
// Get user's first name to personalize the message.
$first_name = $user->first_name;
// Add a custom message to the beginning of the certificate content.
$custom_message = sprintf(
'<p style="text-align: center; font-size: 1.1em; margin-bottom: 20px;">Congratulations, %s! Your hard work and dedication in completing the %s course is truly commendable.</p>',
esc_html( $first_name ),
'Advanced WordPress Development' // You might fetch the course title dynamically here too.
);
$cert_content = $custom_message . $cert_content;
}
}
return $cert_content;
}
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:817
public static function generate_course_content( $cert_content, $args ) {
$user = $args['user'];
$parameters = $args['parameters'];
$cert_content = preg_replace( '/([courseinfo)/', '[courseinfo user_id="' . $user->ID . '" course_id="' . $parameters['course-id'] . '" ', $cert_content );
$cert_content = preg_replace( '/([usermeta)/', '[usermeta user_id="' . $user->ID . '" ', $cert_content );
/**
*
* function modify_pdf_certificate_content( $content, $user_id, $course_id ){
* //enter your modifications or use regex to modify content
* return $content;
* }
*
* add_action( 'ucec_generate_course_certificate_content', 'modify_pdf_certificate_content', 20, 3 );
*/
$cert_content = apply_filters( 'ucec_generate_course_certificate_content', $cert_content, $user->ID, $parameters['course-id'] );
return $cert_content;
}