Filter uncanny-learndash-groups

ulgm_user_welcome_email_body

Filters the body content of the user welcome email sent after group membership is confirmed.

add_filter( 'ulgm_user_welcome_email_body', $callback, 10, 2 );

Description

Filters the content of the user welcome email body. Developers can modify the default email text, including dynamic placeholders like #FirstName, #Username, and #LoginUrl, before it's sent to new users. This hook fires after the default email body is retrieved.


Usage

add_filter( 'ulgm_user_welcome_email_body', 'your_function_name', 10, 2 );

Parameters

$string (mixed)
This parameter contains the raw content of the user welcome email body, which can be filtered by plugins.
$group_id (mixed)
This parameter contains the HTML content or plain text of the user welcome email.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the user welcome email body.
 *
 * This function demonstrates how to modify the default welcome email body
 * by adding a custom message or altering existing placeholders.
 *
 * @param string $string     The current user welcome email body.
 * @param int    $group_id   The ID of the group the user is being added to.
 * @return string The modified user welcome email body.
 */
add_filter( 'ulgm_user_welcome_email_body', 'my_custom_user_welcome_email_body', 10, 2 );

function my_custom_user_welcome_email_body( $string, $group_id ) {

	// Get the current user's display name for a more personalized message.
	// This assumes the filter is called within a context where the current user is known.
	// In a real scenario, you might need to fetch this differently depending on when
	// and where this filter is applied. For demonstration, let's simulate getting it.
	$current_user = wp_get_current_user();
	$first_name   = $current_user->user_firstname ? $current_user->user_firstname : $current_user->user_login;

	// Add a custom message to the end of the email body.
	$custom_message = "nnWelcome aboard, {$first_name}! We're excited to have you as part of our learning community.";

	// Append the custom message to the existing email body.
	$string .= $custom_message;

	// You could also replace placeholders if needed, for example:
	// $string = str_replace( '#SiteUrl', 'My Awesome Learning Platform', $string );

	return $string;
}

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/helpers/shared-variables.php:132

public static function user_welcome_email_body( $group_id = null ) {

		$string = get_option( 'ulgm_user_welcome_email_body', false );

		if ( ! $string ) {
			$string = __( "Hi #FirstName,nnYou have been added to #SiteUrl.nnYour login credentials are:nLogin: #UsernamenPassword: #PasswordnnTo log in, click the link below:n#LoginUrlnn Thanks!", 'uncanny-learndash-groups' );
		}
		if ( null !== $group_id ) {
			$group_id                = self::get_real_group_id( $group_id );
			$new_user_email_override = get_post_meta( $group_id, 'ulgm_override_user_welcome_email', true );
			if ( 'no' !== $new_user_email_override ) {
				$new_user_email_body = get_post_meta( $group_id, 'ulgm_override_user_welcome_email_body', true );
				if ( ! empty( $new_user_email_body ) ) {
					$string = $new_user_email_body;
				}
			}
		}

		return apply_filters( 'ulgm_user_welcome_email_body', wp_unslash( $string ), $group_id );
	}


Scroll to Top