learndash_tcpdf_legacy_ld322
Filters whether to use legacy LD322 PDF generation, before the PDF template updates.
add_filter( 'learndash_tcpdf_legacy_ld322', $callback, 10, 1 );
Description
Controls whether to use legacy PDF certificate generation logic (specifically related to LearnDash version 3.2.2). Developers can filter this to force legacy behavior or disable it for compatibility with newer rendering methods. Defaults to true.
Usage
add_filter( 'learndash_tcpdf_legacy_ld322', 'your_function_name', 10, 1 );
Parameters
-
$cert_args(mixed) - This parameter controls whether to use the legacy LearnDash 3.2.2 certificate generation logic.
Return Value
The filtered value.
Examples
add_filter(
'learndash_tcpdf_legacy_ld322',
function( $use_legacy_define, $cert_args ) {
// This filter hook controls whether to use legacy Learndash 3.2.2 PDF certificate generation logic.
// By default, it's set to true. We can conditionally disable it based on specific criteria.
// For example, if we want to force non-legacy behavior for a particular certificate type,
// or if a specific user role has access to newer features.
// Example: Disable legacy mode if the certificate post type is 'new_certificate_type'.
if ( isset( $cert_args['cert_post'] ) && $cert_args['cert_post']->post_type === 'new_certificate_type' ) {
return false; // Disable legacy mode
}
// Example: Disable legacy mode if a specific GET parameter is set, e.g., ?disable_legacy_cert=1
if ( isset( $_GET['disable_legacy_cert'] ) && $_GET['disable_legacy_cert'] == 1 ) {
return false; // Disable legacy mode
}
// If none of our custom conditions are met, return the original value.
return $use_legacy_define;
},
10, // Priority: Default is 10. Adjust if you need to run before or after other filters.
2 // Accepted Args: This filter accepts two 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:381
$footer_enable = $_GET['footer'];
}
/**
* Start Cert post content processing.
*/
if ( ! defined( 'LEARNDASH_TCPDF_LEGACY_LD322' ) ) {
$use_LD322_define = apply_filters( 'learndash_tcpdf_legacy_ld322', true, $cert_args );
define( 'LEARNDASH_TCPDF_LEGACY_LD322', $use_LD322_define );
}
$cert_content = $cert_args['cert_post']->post_content;
// Delete shortcode for POST2PDF Converter
$cert_content = preg_replace( '|[pdf[^]]*?].*?[/pdf]|i', '', $cert_content );