uo_generate_quiz_certificate_content
function modify_pdf_certificate_content( $cert_content, $user_id, $quiz_id, $course_id ){ //enter your modifications or use regex to modify content return $cert_content; } add_action( 'uo_generate_quiz_certificate_content', 'modify_pdf_certificate_content', 20, 4 ); Filters the content used to generate a quiz certificate before it is outputted.
add_filter( 'uo_generate_quiz_certificate_content', $callback, 10, 2 );
Description
This filter hook allows developers to modify the content of a generated quiz certificate before it's saved or displayed. Developers can use this hook to dynamically alter text, add custom information, or even apply regular expressions to the certificate's content. The hook provides access to the current certificate content, user ID, quiz ID, and course ID for targeted modifications.
Usage
add_filter( 'uo_generate_quiz_certificate_content', 'your_function_name', 10, 2 );
Parameters
-
$cert_content(mixed) - - **$user** `mixed`
-
$quiz_id(mixed) - - **$course_id** `mixed`
Return Value
The filtered value.
Examples
// Example function to add a custom message to the certificate content based on quiz score.
function custom_certificate_message( $cert_content, $user, $quiz_id, $course_id ) {
// We need to fetch the quiz score to determine if we should add a custom message.
// This is a placeholder. In a real scenario, you'd likely use a plugin's API
// or a custom database query to get the user's score for this specific quiz.
// For demonstration, let's assume we can retrieve a score.
$user_quiz_score = get_user_quiz_score( $user->ID, $quiz_id ); // This function needs to be defined or replaced with actual logic.
// Let's assume a score of 90 or above is considered excellent.
if ( $user_quiz_score >= 90 ) {
$custom_message = '<p style="text-align:center; font-style:italic;">Congratulations on your outstanding performance!</p>';
// Append the custom message to the existing certificate content.
// We'll assume $cert_content is a string or HTML.
$cert_content .= $custom_message;
} elseif ( $user_quiz_score >= 70 ) {
$custom_message = '<p style="text-align:center; font-style:italic;">Well done on completing this quiz!</p>';
$cert_content .= $custom_message;
}
// Return the modified certificate content.
return $cert_content;
}
add_filter( 'uo_generate_quiz_certificate_content', 'custom_certificate_message', 10, 4 );
// Placeholder function for getting user's quiz score.
// In a real application, this would interact with your LMS plugin's data.
function get_user_quiz_score( $user_id, $quiz_id ) {
// This is a mock function. Replace with actual logic to fetch the score.
// For example, if using a popular LMS plugin, you might have a function like:
// return TutorLMS()->quiz->get_quiz_final_score( $quiz_id, $user_id );
// Or retrieve from custom post meta or user meta.
// For this example, we'll return a random score for demonstration.
return rand(50, 100);
}
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:1088
* function modify_pdf_certificate_content( $cert_content, $user_id, $quiz_id, $course_id ){
* //enter your modifications or use regex to modify content
* return $cert_content;
* }
*
* add_action( 'uo_generate_quiz_certificate_content', 'modify_pdf_certificate_content', 20, 4 );
*/
$cert_content = apply_filters( 'uo_generate_quiz_certificate_content', $cert_content, $user->ID, $quiz_id, $course_id );
return $cert_content;
}
/**
* @param $atts
*