Filter uncanny-toolkit-pro

uo_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( 'uo_generate_course_certificate_content', 'modify_pdf_certificate_content', 20, 3 ); Filters the content of a course certificate before it is generated, allowing for dynamic modifications.

add_filter( 'uo_generate_course_certificate_content', $callback, 10, 2 );

Description

This filter hook allows developers to modify the content of a course certificate before it's generated. You can directly alter the `$cert_content` string or use regular expressions to make targeted changes. This is useful for customizing certificate text, adding dynamic information, or integrating with other plugins. The hook provides the certificate content, user object, and relevant parameters.


Usage

add_filter( 'uo_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( 'uo_generate_course_certificate_content', 'my_custom_certificate_content_modifier', 10, 3 );

/**
 * Modifies the certificate content by adding custom text and ensuring specific placeholders are present.
 *
 * @param string $cert_content The original certificate content.
 * @param int    $user_id      The ID of the user the certificate is for.
 * @param int    $course_id    The ID of the course the certificate is for.
 *
 * @return string The modified certificate content.
 */
function my_custom_certificate_content_modifier( $cert_content, $user_id, $course_id ) {
	// Get user object for potential display name retrieval
	$user = get_user_by( 'id', $user_id );

	// Add a custom introductory message before any existing content
	$custom_intro = sprintf( '<p style="text-align:center; font-size:16px;">Congratulations to <strong>%s</strong> for successfully completing the course!</p><br>', esc_html( $user->display_name ) );
	$cert_content = $custom_intro . $cert_content;

	// Ensure a specific placeholder for the completion date is present, or add a default if missing
	if ( strpos( $cert_content, '[completion_date]' ) === false ) {
		$cert_content = str_replace( '[courseinfo', '[courseinfo completion_date="' . current_time( 'mysql' ) . '"', $cert_content );
	}

	// You could also dynamically add course-specific information using the $course_id
	$course_title = get_the_title( $course_id );
	$cert_content .= sprintf( '<p style="text-align:center; font-size:10px;">Course: %s</p>', esc_html( $course_title ) );

	// Important: Always return the modified content from a filter hook.
	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:927

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( 'uo_generate_course_certificate_content', 'modify_pdf_certificate_content', 20, 3 );
		 */
		$cert_content = apply_filters( 'uo_generate_course_certificate_content', $cert_content, $user->ID, $parameters['course-id'] );

		return $cert_content;
	}


Scroll to Top