uo_generate_group_certificate
Filters the arguments used to generate a group certificate, allowing modification before PDF creation.
add_filter( 'uo_generate_group_certificate', $callback, 10, 3 );
Description
Allows developers to conditionally prevent the generation of a group completion certificate. Modify the returned value to `false` to stop certificate creation. The hook passes arguments related to the certificate's filename, PDF generation parameters, group ID, and user ID.
Usage
add_filter( 'uo_generate_group_certificate', 'your_function_name', 10, 3 );
Parameters
-
$generate_pdf_args(mixed) - This parameter is a boolean that, when set to `false`, prevents the generation of the group certificate.
-
$group_id(mixed) - This parameter contains an array of arguments used to configure the PDF generation process for the group certificate.
-
$user_id(mixed) - This parameter represents the ID of the group for which the certificate is being generated.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'uo_generate_group_certificate' filter.
*
* This filter allows you to conditionally prevent the generation of a group certificate.
* For instance, you might want to prevent generation if the user has already
* completed a similar certification, or if there's a specific business rule
* that dictates no certificate should be issued in certain cases.
*
* @param bool $generate_certificate The default value indicating whether to generate the certificate (true).
* @param array $generate_pdf_args An array of arguments used for PDF generation.
* @param int $group_id The ID of the group.
* @param int $user_id The ID of the user.
*
* @return bool Returns false to prevent certificate generation, or true to allow it.
*/
add_filter( 'uo_generate_group_certificate', function( $generate_certificate, $generate_pdf_args, $group_id, $user_id ) {
// Let's assume we have a custom function to check if a user is a VIP member.
// If the user is a VIP, we might want to skip generating a standard certificate
// and perhaps send a custom notification or a different type of award.
if ( function_exists( 'is_vip_member' ) && is_vip_member( $user_id ) ) {
// Log a message for debugging purposes (optional)
error_log( "Skipping group certificate generation for VIP user ID: {$user_id} in group ID: {$group_id}" );
// Return false to stop the certificate generation process.
return false;
}
// If the user is not a VIP, or if the VIP check function doesn't exist,
// we proceed with the default behavior and allow certificate generation.
return $generate_certificate;
}, 10, 4 ); // Priority 10, accepts 4 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/classes/group-completion-certificate.php:310
'file_name' => $file_name,
'parameters' => $setup_parameters,
),
$group_id,
$user_id
);
//External override if certificate is not needed!
$uo_generate_group_certs = apply_filters( 'uo_generate_group_certificate', true, $generate_pdf_args, $group_id, $user_id );
if ( ! $uo_generate_group_certs ) {
return;
}
$file = self::generate_pdf( $generate_pdf_args );
//Allow custom Link to an upload folder
$http_link = apply_filters( 'uo_group_certificate_http_url', WP_CONTENT_URL . '/uploads/group-certificates/' );