ulgm_redemption_email_to
Filters the recipient email address for the redemption email, allowing customization before it's sent.
add_filter( 'ulgm_redemption_email_to', $callback, 10, 2 );
Description
Filters the recipient email address for redemption emails. Allows developers to modify the email address before the redemption email is sent. This is useful for scenarios where the default user email needs to be overridden or for advanced email routing. The `$user_email` parameter contains the current email address, and `$user_data` provides the associated user details.
Usage
add_filter( 'ulgm_redemption_email_to', 'your_function_name', 10, 2 );
Parameters
-
$user_email(mixed) - This parameter contains the email address of the user to whom the redemption email will be sent.
-
$user_data(mixed) - This parameter contains the email address of the user for whom the redemption email is being sent.
Return Value
The filtered value.
Examples
/**
* Example of how to use the ulgm_redemption_email_to filter.
*
* This example modifies the recipient email address to append a specific tag
* if the user's first name is "Admin". This is purely illustrative and
* might not be a practical use case.
*
* @param string $user_email The current email address of the user.
* @param array $user_data An array containing user data, including 'first_name'.
* @return string The modified email address.
*/
add_filter( 'ulgm_redemption_email_to', function( $user_email, $user_data ) {
// Check if the user's first name is 'Admin' (case-insensitive)
if ( isset( $user_data['first_name'] ) && 'admin' === strtolower( $user_data['first_name'] ) ) {
// Append a specific tag to the email address for administrative users
$user_email .= '+admin_tag';
}
// Always return the potentially modified email address
return $user_email;
}, 10, 2 ); // Priority 10, accepts 2 arguments ($user_email, $user_data)
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-management/class-group-management-helpers.php:1264
src/classes/group-management/class-group-management-helpers.php:1669
public static function resend_redemption_email( $user_data, $redemption_template_subject, $redemption_template_body, $group_id ) {
// Set up user data
$user_email = $user_data['user_email'];
$first_name = $user_data['first_name'];
$last_name = $user_data['last_name'];
// Get the redemption key
$redemption_key = $user_data['key'];
// Filter #EmailEncoded variable
$redemption_template_subject = str_ireplace( '#EmailEncoded', urlencode( $user_email ), $redemption_template_subject );
$redemption_template_body = str_ireplace( '#EmailEncoded', urlencode( $user_email ), $redemption_template_body );
// Filter #email variable
$redemption_template_subject = str_ireplace( '#Email', $user_email, $redemption_template_subject );
$redemption_template_body = str_ireplace( '#Email', $user_email, $redemption_template_body );
// Filter #first_name variable
$redemption_template_subject = str_ireplace( '#FirstName', $first_name, $redemption_template_subject );
$redemption_template_body = str_ireplace( '#FirstName', $first_name, $redemption_template_body );
// Filter #last_name variable
$redemption_template_subject = str_ireplace( '#LastName', $last_name, $redemption_template_subject );
$redemption_template_body = str_ireplace( '#LastName', $last_name, $redemption_template_body );
// Filter #redemption_key variable
$redemption_template_subject = str_ireplace( '#RedemptionKey', $redemption_key, $redemption_template_subject );
$redemption_template_body = str_ireplace( '#RedemptionKey', $redemption_key, $redemption_template_body );
// Filter #SiteUrl variable
$redemption_template_subject = str_ireplace( '#SiteUrl', site_url(), $redemption_template_subject );
$redemption_template_body = str_ireplace( '#SiteUrl', site_url(), $redemption_template_body );
// Filter #LoginUrl variable
$redemption_template_subject = str_ireplace( '#LoginUrl', wp_login_url(), $redemption_template_subject );
$redemption_template_body = str_ireplace( '#LoginUrl', wp_login_url(), $redemption_template_body );
// Filter #GroupLeaderInfo variable
$redemption_template_subject = str_ireplace( '#GroupLeaderInfo', self::get_group_leader_info( $group_id ), $redemption_template_subject );
$redemption_template_body = str_ireplace( '#GroupLeaderInfo', self::get_group_leader_info( $group_id ), $redemption_template_body );
// Filter #Courses variable
$redemption_template_subject = str_ireplace( '#Courses', self::get_group_courses( $group_id ), $redemption_template_subject );
$redemption_template_body = str_ireplace( '#Courses', self::get_group_courses( $group_id ), $redemption_template_body );
// Remove escaped apostrophes
$redemption_template_subject = str_replace( "'", "'", $redemption_template_subject );
$redemption_template_body = str_replace( "'", "'", $redemption_template_body );
$to = apply_filters( 'ulgm_redemption_email_to', $user_email, $user_data );
$subject = apply_filters( 'ulgm_redemption_email_subject', $redemption_template_subject, $user_data );
$body = apply_filters( 'ulgm_redemption_email_body', $redemption_template_body, $user_data );
if ( ! class_exists( 'WP_Better_Emails' ) || ( false === preg_match( '/<DOCTYPE/', $body ) && false === preg_match( '/<head>/', $body ) ) ) {
$body = wpautop( $body );
}
$send_mail = apply_filters( 'ulgm_maybe_resend_redemption_email', true, $to, $subject, $group_id );
if ( $send_mail ) {
$redemption_email = SharedFunctions::wp_mail( $to, $subject, $body, self::get_headers() );
//If the mail is successful let a a fake user and group meta
if ( is_wp_error( $redemption_email ) ) {
return false;
}
}
return true;
}