Filter
uncanny-automator-pro
automator_generate_course_certificate_tcpdf_dest
Filters the destination path for LearnDash course certificates generated with the TCPDF integration before saving.
add_filter( 'automator_generate_course_certificate_tcpdf_dest', $callback, 10, 1 );
Description
Filters the destination for saving LearnDash course certificates generated by TCPDF. Allows developers to specify an alternative file path or method for saving the PDF, beyond the default 'F' (save to local file).
Usage
add_filter( 'automator_generate_course_certificate_tcpdf_dest', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of using the 'automator_generate_course_certificate_tcpdf_dest' filter hook.
* This filter allows you to modify the destination for saving the generated PDF certificate.
*
* By default, Uncanny Automator saves the certificate as a file ('F').
* This example demonstrates how to change the destination to force download
* the certificate to the user's browser ('D') if a specific condition is met.
*/
add_filter(
'automator_generate_course_certificate_tcpdf_dest',
function ( $destination ) {
// In a real-world scenario, you might have logic here to determine
// if the destination should be changed. For example, you might check
// user meta, a specific recipe setting, or a global flag.
// For demonstration purposes, let's assume we want to force download
// the certificate for users with a specific role.
if ( current_user_can( 'administrator' ) ) {
// Change the destination to 'D' for inline display in the browser
// or 'F' for saving to a file, 'I' for inline display.
// 'D' - Send the file inline to the browser. The PDF viewer
// will be used to display the PDF, and the name given
// by name parameter will be used. The default name is relative
// to the root directory, may be ignored.
// 'F' - Save the file on the server. The path is absolute or relative to the
// root directory.
// 'I' - Send the file inline to the browser. The PDF viewer will be used
// to display the PDF.
return 'D';
}
// If the condition is not met, return the original destination.
return $destination;
},
10, // Priority (default is 10)
1 // Accepted arguments (only $destination is passed)
);
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
uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:1159
$full_path = $save_path . $file_name . '.pdf';
switch ( $certificate_type ) {
case 'quiz':
$output = apply_filters( 'automator_generate_quiz_certificate_tcpdf_dest', 'F' );
break;
case 'course':
$output = apply_filters( 'automator_generate_course_certificate_tcpdf_dest', 'F' );
break;
case 'automator':
$output = apply_filters( 'automator_certificate_tcpdf_dest', 'F' );
break;
default:
$output = apply_filters( 'automator_generate_quiz_certificate_tcpdf_dest', 'I' );
break;