uo_generate_group_certificate_tcpdf_dest
Filters the destination for TCPDF certificate generation, allowing modification before the file is saved.
add_filter( 'uo_generate_group_certificate_tcpdf_dest', $callback, 10, 1 );
Description
Filters the destination for generated group certificates using TCPDF. Allows developers to customize where the PDF is saved, for example, to a different directory or to be output directly to the browser. Defaults to saving locally as 'F'.
Usage
add_filter( 'uo_generate_group_certificate_tcpdf_dest', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to modify the destination for generating group certificates using TCPDF.
*
* This filter allows you to change how the generated PDF certificate is outputted.
* The default behavior of 'F' is to save the file to the server's filesystem.
* You might want to change this to 'I' to force download, 'S' to get the string, etc.
*
* @param string $destination The current destination type for the TCPDF output.
* 'F' means save to a local file.
* 'I' means send inline to the browser.
* 'D' means send to the browser as a download.
* 'S' means return the document as a string.
* @return string The modified destination type.
*/
add_filter( 'uo_generate_group_certificate_tcpdf_dest', 'my_custom_group_certificate_destination', 10, 1 );
function my_custom_group_certificate_destination( $destination ) {
// For demonstration purposes, let's say we want to always force download
// if the certificate type is 'group'.
// In a real scenario, you might check other conditions like user roles,
// specific group settings, or even a custom option set in the WordPress admin.
// Let's assume you have a custom option in WordPress settings to control this.
// Replace 'my_option_force_download_group_certs' with your actual option name.
$force_download = get_option( 'my_option_force_download_group_certs', false );
if ( $force_download ) {
return 'D'; // Send to the browser as a download
}
// If the custom option is not set to force download, return the original destination.
// This ensures that if the original value was 'F' (save locally), it remains 'F'.
return $destination;
}
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:811
$full_path = $save_path . $file_name . '.pdf';
switch ( $certificate_type ) {
case 'quiz':
$output = apply_filters( 'uo_generate_quiz_certificate_tcpdf_dest', 'F' );
break;
case 'group':
$output = apply_filters( 'uo_generate_group_certificate_tcpdf_dest', 'F' );
break;
case 'course':
$output = apply_filters( 'uo_generate_course_certificate_tcpdf_dest', 'F' );
break;
case 'preivew':
default:
$output = apply_filters( 'uo_generate_preview_certificate_tcpdf_dest', 'I' );