uo_enable_mail_user_group_certificates
Filters whether to send email to user groups for certificates, allowing customization of this core functionality.
add_filter( 'uo_enable_mail_user_group_certificates', $callback, 10, 1 );
Description
Allows developers to control whether an email containing a group completion certificate is sent to the user. By default, emails are enabled. Returning `false` will prevent the email from being sent. This filter fires before the `wp_mail` function is called.
Usage
add_filter( 'uo_enable_mail_user_group_certificates', 'your_function_name', 10, 1 );
Parameters
-
$email_params(mixed) - This parameter is a boolean value that determines whether emails for group completion certificates should be sent to users.
Return Value
The filtered value.
Examples
/**
* Conditionally disable sending group completion certificates via email to users.
*
* This filter allows administrators to disable the automatic email of group
* completion certificates to users, for example, during testing or if a
* different notification method is preferred.
*
* @param bool $enable_mail Whether to enable email notifications for group certificates.
* @param array $email_params An array containing email parameters like 'email', 'subject', and 'msg'.
* @return bool True to enable email, false to disable.
*/
function my_disable_group_certificate_email( $enable_mail, $email_params ) {
// Prevent sending email if the user's email is empty or if a specific condition is met.
// For example, if the certificate is for a specific group that should not be emailed.
if ( empty( $email_params['email'] ) ) {
return false; // Do not send if there's no recipient email.
}
// Example: Disable email for a specific group if its name is "Testing Group".
// You would need to dynamically get the group name or have a way to identify it.
// This is a simplified example; in a real scenario, you might pass group ID or name.
$group_name_to_disable = 'Testing Group'; // Replace with actual group identification logic.
if ( isset( $email_params['group_name'] ) && $email_params['group_name'] === $group_name_to_disable ) {
return false; // Disable email for this specific group.
}
// By default, allow the email to be sent.
return $enable_mail;
}
add_filter( 'uo_enable_mail_user_group_certificates', 'my_disable_group_certificate_email', 10, 2 );
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:442
//Sending Email To User!
$change_content_type = apply_filters( 'uo_apply_wp_mail_content_type', true );
if ( $change_content_type ) {
add_filter( 'wp_mail_content_type', array( __CLASS__, 'mail_content_type' ) );
}
$enable_mail_user = apply_filters( 'uo_enable_mail_user_group_certificates', true, $email_params );
if ( true === $enable_mail_user ) {
wp_mail( $email_params['email'], $email_params['subject'], $email_params['msg'], $headers, $file );
}
if ( 'on' === $is_admin ) {
$non_user_body = str_ireplace( '%Group Name%', $ugroups, $non_user_body );
$change_content_type = apply_filters( 'uo_apply_wp_mail_content_type', true );