Filter Since 2.4.7 uncanny-continuing-education-credits

learndash_certificate_params

Filters certificate tcpdf paramaters. Filters the TCPDF parameters used to generate a LearnDash certificate, allowing modification before the PDF is created.

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

Description

Modify TCPDF parameters for LearnDash certificates. This filter hook, `learndash_certificate_params`, allows developers to adjust the core TCPDF settings before a certificate PDF is generated. You can change parameters like orientation, unit, format, and unicode. The hook provides the current parameter array and the certificate's post ID for context.


Usage

add_filter( 'learndash_certificate_params', 'your_function_name', 10, 2 );

Parameters

$tcpdf_params (array)
An array of tcpdf parameters.
$cert_id (int)
Certificate post ID.

Return Value

The filtered value.


Examples

add_filter( 'learndash_certificate_params', 'my_learndash_custom_certificate_params', 10, 2 );

/**
 * Customizes LearnDash certificate TCPDF parameters.
 *
 * This function modifies the default TCPDF parameters for LearnDash certificates
 * to adjust the page format and orientation for a specific certificate.
 *
 * @param array $tcpdf_params An array of tcpdf parameters.
 * @param int   $cert_id      Certificate post ID.
 * @return array Modified tcpdf_params array.
 */
function my_learndash_custom_certificate_params( $tcpdf_params, $cert_id ) {
    // Check if this is a specific certificate we want to modify.
    // Replace '12345' with the actual ID of the certificate you want to customize.
    if ( $cert_id === 12345 ) {
        // Change the page format to A4 landscape.
        $tcpdf_params['format'] = 'A4-L'; // Landscape orientation
        $tcpdf_params['orientation'] = 'L'; // Explicitly set orientation
    }

    // You can add more conditional logic here for other certificate IDs.
    // For example, to set a different format for another certificate:
    /*
    if ( $cert_id === 67890 ) {
        $tcpdf_params['format'] = 'Letter-P'; // Letter portrait
        $tcpdf_params['orientation'] = 'P';
    }
    */

    // Always return the modified parameters.
    return $tcpdf_params;
}

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

*
		 * @param array $tcpdf_params An array of tcpdf parameters.
		 * @param int $cert_id Certificate post ID.
		 *
		 * @since 2.4.7
		 *
		 */
		$tcpdf_params = apply_filters( 'learndash_certificate_params', $tcpdf_params, $cert_args['cert_id'] );

		$pdf = new TCPDF(
			$tcpdf_params['orientation'],
			$tcpdf_params['unit'],
			$tcpdf_params['format'],
			$tcpdf_params['unicode'],
			$tcpdf_params['encoding'],


Scroll to Top