uo_user_mail_headers
Filters the email headers used for user-related emails to allow for modification before sending.
add_filter( 'uo_user_mail_headers', $callback, 10, 1 );
Description
Fires before sending user emails, allowing modification of email headers like 'To', 'From', and 'Subject'. Developers can alter recipient, sender, or subject line dynamically, for example, to add custom headers or personalize subject content.
Usage
add_filter( 'uo_user_mail_headers', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
add_filter( 'uo_user_mail_headers', 'my_custom_user_mail_headers', 10, 1 );
/**
* Example function to modify the email headers for user emails.
*
* This function demonstrates how to add custom headers, such as a 'Reply-To' address.
*
* @param array $headers The existing email headers.
* @return array The modified email headers.
*/
function my_custom_user_mail_headers( $headers ) {
// Ensure $headers is always an array.
if ( ! is_array( $headers ) ) {
$headers = array();
}
// Add a custom Reply-To header.
$headers[] = 'Reply-To: [email protected]';
// You could also add other standard email headers like CC or BCC if needed.
// For example:
// $headers[] = 'Cc: [email protected]';
return $headers;
}
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/award-certificate.php:693
$email_subject = str_ireplace( '%User First Name%', $current_user->first_name, $email_subject );
$email_subject = str_ireplace( '%User Last Name%', $current_user->last_name, $email_subject );
$email_subject = str_ireplace( '%User Email%', $current_user->user_email, $email_subject );
$email_subject = str_ireplace( '%Group Name%', '', $email_subject );
$email_subject = str_ireplace( '%Courses%', join( ', ', $course_names ), $email_subject );
//Sending email to user first
$user_mail_headers = apply_filters( 'uo_user_mail_headers', array() );
wp_mail( $current_user->user_email, $email_subject, $email_message, $user_mail_headers, $certificate );
//Now let's see if we want to send email to admin and group leader
$is_admin = get_option( 'uncanny-ceu-multiple-notify-admin', 'no' );
$is_group_admin = get_option( 'uncanny-ceu-multiple-notify-group-leader', 'no' );
$email_subject = str_ireplace( 'You earned', $current_user->first_name . ' earned', $email_subject );