Filter uncanny-learndash-groups

ulgm_welcome_email_body

Filters the welcome email body content before it's sent to a user joining a group.

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

Description

Filters the HTML body content of the welcome email sent to new group members. Developers can modify the email's text, add custom content, or completely replace the default body using this hook. It's applied just before the email is sent, allowing for dynamic content based on user and group data.


Usage

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

Parameters

$welcome_template_body (mixed)
This parameter contains the HTML content of the welcome email template.
$user_data (mixed)
This parameter contains the HTML content of the welcome email template.
$group_name (mixed)
This parameter contains an array of data related to the user receiving the welcome email.

Return Value

The filtered value.


Examples

<?php
/**
 * Add custom content to the welcome email body for a specific group.
 *
 * This filter allows developers to modify the welcome email sent to users
 * when they are added to a group. In this example, we're appending a
 * custom message if the user is added to the 'Premium Members' group.
 *
 * @param string $welcome_template_body The current HTML content of the welcome email body.
 * @param array  $user_data             An array containing user information (e.g., 'user_login', 'first_name', 'last_name').
 * @param string $group_name            The name of the group the user is being added to.
 * @return string The modified HTML content of the welcome email body.
 */
add_filter( 'ulgm_welcome_email_body', function( $welcome_template_body, $user_data, $group_name ) {

	// Check if the user is being added to a specific group.
	if ( 'Premium Members' === $group_name ) {
		// Get the user's first name, defaulting to 'there' if not available.
		$first_name = isset( $user_data['first_name'] ) && ! empty( $user_data['first_name'] ) ? $user_data['first_name'] : 'there';

		// Construct the custom message to append.
		$custom_message = sprintf(
			'<p>Welcome, %s! As a Premium Member, you now have access to exclusive content and resources. We're thrilled to have you!</p>',
			esc_html( $first_name )
		);

		// Append the custom message to the existing email body.
		// It's generally good practice to append rather than overwrite,
		// unless you have a specific reason to replace the entire content.
		$welcome_template_body .= $custom_message;
	}

	// Always return the modified (or unmodified) email body.
	return $welcome_template_body;

}, 10, 3 ); // Priority 10, accepts 3 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-management/class-group-management-helpers.php:1379

'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 );
		}

		$send_mail = apply_filters( 'ulgm_maybe_send_welcome_email', true, $to, $subject, $group_id );
		if ( $send_mail ) {


Scroll to Top