uo_learndash_certificate_subsetting_enable
Filters whether LearnDash certificate subsetting is enabled for specific certificate arguments.
add_filter( 'uo_learndash_certificate_subsetting_enable', $callback, 10, 2 );
Description
Controls whether font subsetting is enabled for LearnDash certificates. Developers can use this filter to programmatically disable or enable subsetting, perhaps based on specific certificate IDs or other conditional logic, overriding the default GET parameter behavior.
Usage
add_filter( 'uo_learndash_certificate_subsetting_enable', 'your_function_name', 10, 2 );
Parameters
-
$subsetting_enable(mixed) - This parameter controls whether font subsetting is enabled for LearnDash certificates, defaulting to a value potentially set by a GET parameter.
-
$cert_args(mixed) - This parameter determines whether font subsetting is enabled for LearnDash certificates.
Return Value
The filtered value.
Examples
<?php
/**
* Conditionally disable subsetting for LearnDash certificates based on user role.
*
* This filter allows administrators (or users with a specific role) to enable
* subsetting by default, while other users might have it disabled.
*
* @param mixed $subsetting_enable The current value of the subsetting enable flag.
* @param int $cert_id The ID of the certificate being generated.
* @return mixed The modified subsetting enable flag.
*/
add_filter( 'uo_learndash_certificate_subsetting_enable', function( $subsetting_enable, $cert_id ) {
// Assume subsetting is enabled by default if not explicitly set via GET.
// If it's already set via GET, we respect that value.
if ( ! isset( $_GET['subsetting'] ) ) {
// Check if the current user has the 'administrator' role.
if ( current_user_can( 'manage_options' ) ) {
// Administrators can force subsetting to be enabled for better font handling in some cases.
$subsetting_enable = 1;
} else {
// For other users, we might want to disable subsetting by default for simplicity
// or if there are known issues with subsetting on their setups.
$subsetting_enable = 0;
}
}
// If $_GET['subsetting'] was provided, it would have already set $subsetting_enable
// before this filter is applied, so we don't need to override it here unless
// we want to add further logic based on the certificate ID.
// For example, if a specific certificate ID is known to have font issues with subsetting,
// we could disable it regardless of user role or GET parameter.
// if ( $cert_id === 123 ) {
// $subsetting_enable = 0;
// }
return $subsetting_enable;
}, 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:367
$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 ) ) {
$subsetting_enable = $_GET['subsetting'];
}
$subsetting_enable = apply_filters( 'uo_learndash_certificate_subsetting_enable', $subsetting_enable, $cert_args['cert_id'] );
if ( $subsetting_enable == 1 ) {
$subsetting = 'true';
} else {
$subsetting = 'false';
}