Filter uncanny-learndash-groups

ulgm_welcome_email_to

Filters the recipient email address for the welcome email sent to new group members.

add_filter( 'ulgm_welcome_email_to', $callback, 10, 3 );

Description

Fires before a welcome email is sent to a new user joining a group. Developers can modify the recipient's email address, allowing for custom email routing or conditional sending. The original user email and group name are provided for context.


Usage

add_filter( 'ulgm_welcome_email_to', 'your_function_name', 10, 3 );

Parameters

$user_email (mixed)
This parameter contains the email address of the user to whom the welcome email will be sent.
$user_data (mixed)
This parameter contains the email address of the user to whom the welcome email is being sent.
$group_name (mixed)
This parameter contains an array of user data including their ID, login, first name, and last name.

Return Value

The filtered value.


Examples

/**
 * Modify the recipient email address for the welcome email.
 *
 * This filter can be used to send the welcome email to a different address,
 * for example, to a specific admin email for moderation purposes,
 * or to a different user depending on certain conditions.
 *
 * @param string $user_email The original recipient email address.
 * @param array  $user_data  An array containing user data (id, email, login, first_name, last_name).
 * @param string $group_name The name of the group the user is being added to.
 * @return string The modified recipient email address.
 */
add_filter( 'ulgm_welcome_email_to', function( $user_email, $user_data, $group_name ) {
    // Example: If the user is being added to a specific group, send a copy of the welcome email to an admin.
    if ( 'Premium Members' === $group_name ) {
        $admin_email = get_option( 'admin_email' );
        // We can return an array of emails to send to multiple recipients.
        // In this case, we'll send it to the user and CC the admin.
        return array( $user_email, $admin_email );
    }

    // Example: If the user's first name starts with 'J', send the email to a secondary address for special handling.
    if ( isset( $user_data['first_name'] ) && substr( $user_data['first_name'], 0, 1 ) === 'J' ) {
        return '[email protected]';
    }

    // If no modifications are needed, return the original email address.
    return $user_email;
}, 10, 3 );

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:1377

'user_id'    => $user_id,
			'user_email' => $user_email,
			'user_login' => $user_login,
			'first_name' => $first_name,
			'last_name'  => $last_name,
		);

		$to      = apply_filters( 'ulgm_welcome_email_to', $user_email, $user_data, $group_name );
		$subject = apply_filters( 'ulgm_welcome_email_subject', $welcome_template_subject, $user_data, $group_name );
		$body    = apply_filters( 'ulgm_welcome_email_body', $welcome_template_body, $user_data, $group_name );

		if ( ! class_exists( 'WP_Better_Emails' ) || ( false === preg_match( '/<DOCTYPE/', $body ) && false === preg_match( '/<head>/', $body ) ) ) {
			$body = wpautop( $body );
		}


Scroll to Top