Filter uncanny-learndash-groups

ulgm_welcome_email_subject

Filters the subject line for the user welcome email, allowing customization before it's sent.

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

Description

Filter the subject line of the welcome email sent to new group members. Developers can modify the default subject to customize notifications. The hook passes the current subject, user data, and group name for dynamic manipulation.


Usage

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

Parameters

$welcome_template_subject (mixed)
The default subject line for the welcome email.
$user_data (mixed)
This parameter contains the default subject line for the welcome email.
$group_name (mixed)
This parameter contains an array of the user's data, including their email, login, first name, and last name.

Return Value

The filtered value.


Examples

/**
 * Filters the subject of the welcome email to include the group name.
 *
 * This function demonstrates how to modify the default welcome email subject
 * to dynamically include the name of the group the user has joined.
 *
 * @param string $welcome_template_subject The original welcome email subject.
 * @param array  $user_data                An array containing user data (e.g., 'user_email', 'user_login', 'first_name', 'last_name').
 * @param string $group_name               The name of the group the user has joined.
 *
 * @return string The modified welcome email subject.
 */
add_filter(
	'ulgm_welcome_email_subject',
	function ( $welcome_template_subject, $user_data, $group_name ) {
		// If the group name is not empty, prepend it to the subject.
		if ( ! empty( $group_name ) ) {
			// Example: Change "Welcome to our platform!" to "Welcome to [Group Name]! Your account is ready."
			$modified_subject = sprintf(
				__( 'Welcome to %s! Your account is ready.', 'your-text-domain' ),
				esc_html( $group_name )
			);
		} else {
			// Fallback to the original subject if no group name is provided.
			$modified_subject = $welcome_template_subject;
		}

		// You could also add user-specific information if needed, for example:
		// if ( ! empty( $user_data['first_name'] ) ) {
		//     $modified_subject = sprintf(
		//         __( 'Hello %s, welcome to %s!', 'your-text-domain' ),
		//         esc_html( $user_data['first_name'] ),
		//         esc_html( $group_name )
		//     );
		// }

		return $modified_subject;
	},
	10, // Priority: Default is 10.
	3   // Accepted args: The number of arguments the callback function 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/group-management/class-group-management-helpers.php:1378

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

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


Scroll to Top