Filter uncanny-learndash-groups

ulgm_exiting_user_welcome_email_body

Filters the body content of the welcome email sent when a user exits a group.

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

Description

Filters the body content of the welcome email sent to existing users when added to a new group. Developers can modify the email's text, add custom information, or change its structure before it's sent. The `$group_id` parameter allows for group-specific email content.


Usage

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

Parameters

$string (mixed)
This parameter contains the body of the welcome email for existing users, which can be a string or false if no option is set.
$group_id (mixed)
This parameter contains the body of the welcome email for existing users, which can be dynamically filtered.

Return Value

The filtered value.


Examples

/**
 * Modify the welcome email body for existing users.
 *
 * This function demonstrates how to hook into the 'ulgm_exiting_user_welcome_email_body'
 * filter to customize the content of the welcome email sent to users who are
 * already part of the site but are being added to a new group.
 *
 * In this example, we'll add a specific mention of the group name to the email
 * if the group name is available.
 */
add_filter( 'ulgm_exiting_user_welcome_email_body', function( $email_body, $group_id ) {

	// If a group ID is provided and we can retrieve its name, append it to the email body.
	if ( $group_id && is_numeric( $group_id ) ) {
		$group_post = get_post( $group_id );
		if ( $group_post && 'groups' === $group_post->post_type ) {
			// Append the group name to the existing email body.
			// We'll add a newline for better formatting.
			$email_body .= "nnYour new group is: " . esc_html( $group_post->post_title );
		}
	}

	// Return the potentially modified email body.
	return $email_body;

}, 10, 2 ); // 10 is the priority, 2 is the number of arguments the callback accepts.

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

public static function exiting_user_welcome_email_body( $group_id = null ) {

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

		if ( ! $string ) {
			$string = sprintf( __( "Hi #FirstName,nnYou have been added to a new group on #SiteUrl!nnTo access your new %s, log in here:n#LoginUrlnnThanks!", 'uncanny-learndash-groups' ), LearnDash_Custom_Label::get_label( 'courses' ) );
		}
		if ( null !== $group_id ) {
			$group_id                     = self::get_real_group_id( $group_id );
			$existing_user_email_override = get_post_meta( $group_id, 'ulgm_override_existing_user_welcome_email', true );
			if ( 'no' !== $existing_user_email_override ) {
				$existing_user_email_body = get_post_meta( $group_id, 'ulgm_override_existing_user_welcome_email_body', true );
				if ( ! empty( $existing_user_email_body ) ) {
					$string = $existing_user_email_body;
				}
			}
		}

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


Scroll to Top