Action Since 3.3.0 uncanny-toolkit-pro

learndash_certification_content_write_cell_after

Fires after the certificate content is added to the PDF. Fires after LearnDash certificate content is added to the PDF, providing access to the TCPDF instance and certificate arguments.

add_action( 'learndash_certification_content_write_cell_after', $callback, 10, 1 );

Description

Fires after the core certificate content has been written to the PDF. Developers can hook into this action to add custom elements, modify existing ones, or perform actions before background color and padding are set on the `$pdf` object. The `$cert_args` array provides access to certificate generation parameters.


Usage

add_action( 'learndash_certification_content_write_cell_after', 'your_function_name', 10, 1 );

Examples

/**
 * Adds a custom watermark to the LearnDash certificate PDF after content is rendered.
 *
 * This function hooks into the `learndash_certification_content_write_cell_after` action
 * to inject additional content into the generated PDF certificate.
 *
 * @param TCPDF $pdf       The TCPDF object instance.
 * @param array  $cert_args An array containing arguments related to the certificate generation.
 */
add_action( 'learndash_certification_content_write_cell_after', function( $pdf, $cert_args ) {

    // Ensure we have the necessary arguments.
    if ( ! is_array( $cert_args ) || empty( $cert_args['user_id'] ) || empty( $cert_args['course_id'] ) ) {
        return;
    }

    $user_id = $cert_args['user_id'];
    $course_id = $cert_args['course_id'];

    // Define watermark text. You could dynamically generate this based on user/course.
    $watermark_text = 'DRAFT - ' . strtoupper( get_the_title( $course_id ) );

    // Set watermark properties.
    $pdf->SetAlpha(0.2); // Transparency
    $pdf->SetFont('helvetica', 'B', 60); // Font, style, size
    $pdf->SetTextColor(128, 128, 128); // Gray color

    // Calculate watermark position (center of the page).
    $page_width = $pdf->getPageWidth();
    $page_height = $pdf->getPageHeight();
    $text_width = $pdf->getStringWidth($watermark_text);

    // Move to the center of the page.
    $pdf->setXY( ( $page_width - $text_width ) / 2, ( $page_height / 2 ) - 30 ); // Adjust y for vertical centering

    // Rotate the text for a diagonal watermark.
    $pdf->StartTransform();
    $pdf->Rotate( -45 );

    // Output the watermark text.
    $pdf->Cell( 0, 0, $watermark_text, 0, 0, 'C', false, '', 0, false, 0, 0 );

    // End transform and reset alpha.
    $pdf->StopTransform();
    $pdf->SetAlpha(1.0); // Reset transparency

}, 10, 2 ); // Priority 10, accepts 2 arguments.

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:795

* Fires after the certificate content is added to the PDF.
		 *
		 * @param TCPDF $pdf `TCPDF` class instance.
		 * @param array $cert_args Array of certificate args.
		 *
		 * @since 3.3.0
		 */
		do_action( 'learndash_certification_content_write_cell_after', $pdf, $cert_args );

		// Set background
		$pdf->SetFillColor( 255, 255, 127 );
		$pdf->setCellPaddings( 0, 0, 0, 0 );
		// Print signature

		ob_clean();


Scroll to Top