Filter uncanny-toolkit-pro

uo_learndash_certificate_monospaced_font

Filters the monospaced font used for LearnDash certificates before they are generated.

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

Description

This filter allows developers to modify the monospaced font used for LearnDash certificates. It's applied when a monospaced font is specified via GET parameters or determined by the core system. Developers can use this to override the default monospaced font with their own custom choice.


Usage

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

Parameters

$monospaced_font (mixed)
This parameter contains the font name for monospaced text on the certificate, which can be filtered to change the default.
$cert_args (mixed)
This parameter holds the name of the monospaced font to be used for the certificate.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the monospaced font for LearnDash certificates.
 *
 * This function allows you to override the default monospaced font used for
 * certain elements on a LearnDash certificate. For instance, if you want to
 * ensure a specific monospaced font like 'Courier New' is always used, you can
 * use this filter.
 *
 * @param string $monospaced_font The current monospaced font being used.
 * @param int    $cert_id         The ID of the certificate being generated.
 * @return string The modified or original monospaced font.
 */
add_filter( 'uo_learndash_certificate_monospaced_font', function( $monospaced_font, $cert_id ) {
	// Always enforce 'Courier New' as the monospaced font for this certificate ID.
	// In a real-world scenario, you might have more complex logic,
	// perhaps checking user roles, course settings, or specific certificate designs.
	if ( $cert_id === 123 ) { // Example: Only apply this to certificate ID 123
		return 'Courier New';
	}

	// If the specific certificate ID doesn't match, return the original font.
	return $monospaced_font;
}, 10, 2 );

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

$font = esc_html( $_GET['font'] );
		}
		$font = apply_filters( 'uo_learndash_certificate_font', $font, $cert_args['cert_id'] );

		if ( ! empty( $_GET['monospaced'] ) ) {
			$monospaced_font = esc_html( $_GET['monospaced'] );
		}
		$monospaced_font = apply_filters( 'uo_learndash_certificate_monospaced_font', $monospaced_font, $cert_args['cert_id'] );

		if ( ! empty( $_GET['fontsize'] ) ) {
			$font_size = intval( $_GET['fontsize'] );
		}
		$font_size = apply_filters( 'uo_learndash_certificate_font_size', $font_size, $cert_args['cert_id'] );

		if ( ! empty( $_GET['subsetting'] ) && ( $_GET['subsetting'] == 1 || $_GET['subsetting'] == 0 ) ) {


Scroll to Top