uo_group_completion_generate_pdf_args
Filters arguments used to generate a group completion PDF, allowing modification before PDF creation.
add_filter( 'uo_group_completion_generate_pdf_args', $callback, 10, 3 );
Description
Allows modification of arguments used for PDF generation for group completion certificates. Developers can filter this hook to change the certificate post object, save path, user details, and filename before the PDF is created. This provides granular control over the PDF output.
Usage
add_filter( 'uo_group_completion_generate_pdf_args', 'your_function_name', 10, 3 );
Parameters
-
$certificate_post(mixed) - This parameter contains the post object of the certificate that is being generated.
-
$group_id(mixed) - This parameter holds the WordPress post object representing the certificate.
-
$user_id(mixed) - This parameter represents the unique identifier of the group for which the certificate is being generated.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Modify PDF generation arguments to add custom metadata to the certificate.
*
* This filter allows you to alter the arguments passed to the PDF generation function
* for group completion certificates. In this example, we're adding a custom key-value
* pair to the 'parameters' array, which might be used by the PDF generation library
* to embed additional information within the PDF.
*
* @param array $generate_pdf_args An array of arguments for PDF generation.
* Expected keys: 'certificate_post', 'save_path', 'user', 'file_name', 'parameters'.
* @param WP_Post $certificate_post The WordPress post object representing the certificate template.
* @param int $group_id The ID of the group for which the certificate is being generated.
* @param int $user_id The ID of the user who completed the group.
* @return array The modified array of arguments for PDF generation.
*/
add_filter( 'uo_group_completion_generate_pdf_args', function( $generate_pdf_args, $certificate_post, $group_id, $user_id ) {
// Ensure we have the expected 'parameters' array and add our custom data.
if ( ! isset( $generate_pdf_args['parameters'] ) || ! is_array( $generate_pdf_args['parameters'] ) ) {
$generate_pdf_args['parameters'] = array();
}
// Add a custom key 'completion_date' with the current date as an example.
// In a real scenario, you might fetch this from user meta or another source.
$generate_pdf_args['parameters']['completion_date'] = date( 'Y-m-d H:i:s' );
// You could also potentially modify other arguments like 'file_name' or 'save_path'
// if needed, but be cautious to not break the core functionality.
return $generate_pdf_args;
}, 10, 4 );
?>
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/classes/group-completion-certificate.php:297
throw new RuntimeException( sprintf( 'Directory "%s" was not created', $save_path ) );
}
$full_path = $save_path . $file_name;
self::$pdf_filename = $full_path;
//Allow PDF args to be modified
$generate_pdf_args = apply_filters(
'uo_group_completion_generate_pdf_args',
array(
'certificate_post' => $certificate_post,
'save_path' => $save_path,
'user' => $user,
'file_name' => $file_name,
'parameters' => $setup_parameters,