Filter Since 3.5.1 uncanny-learndash-groups

ld_group_email_users_personalize_subject

New filters added for email subject and body. Filters the email subject for group messages to personalize it for each user and group.

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

Description

Filters the subject line for emails sent to group members. Developers can use this hook to dynamically personalize email subjects based on user or group email data. The hook provides access to the original subject, user details, and group email content for customization.


Usage

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

Parameters

$mail_args (mixed)
- **$user_data** `mixed`
$group_email_data (mixed)

Return Value

The filtered value.


Examples

/**
 * Example: Customize the subject line of emails sent to users within a LearnDash group.
 *
 * This filter allows developers to dynamically modify the email subject based on
 * the user's data and the group email details. For instance, you might want to
 * add the group name or a specific course title to the subject.
 *
 * @param string $subject          The original email subject.
 * @param array  $user_data        An array containing data for the user being emailed.
 * @param array  $group_email_data An array containing data about the group email being sent.
 *
 * @return string The modified email subject.
 */
add_filter( 'ld_group_email_users_personalize_subject', function( $subject, $user_data, $group_email_data ) {

	// Ensure we have valid data before proceeding.
	if ( ! empty( $user_data['display_name'] ) && ! empty( $group_email_data['group_id'] ) ) {

		// Attempt to get the group name.
		$group_title = get_the_title( $group_email_data['group_id'] );

		// If we have a group title, prepend it to the subject.
		if ( $group_title ) {
			$subject = sprintf( '[%s] %s', sanitize_text_field( $group_title ), $subject );
		}

		// Optionally, you could add user-specific elements.
		// For example, if the email is about a specific course within the group:
		// if ( ! empty( $group_email_data['course_id'] ) ) {
		//     $course_title = get_the_title( $group_email_data['course_id'] );
		//     if ( $course_title ) {
		//         $subject = sprintf( '%s - %s', $subject, sanitize_text_field( $course_title ) );
		//     }
		// }
	}

	return $subject;

}, 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/helpers/rest-api-end-points.php:853

}

			/**
			 * New filters added for email subject and body.
			 *
			 * @since 3.5.1
			 */
			$mail_args_subject    = apply_filters( 'ld_group_email_users_personalize_subject', $mail_args['subject'], $user_data, $group_email_data );
			$mail_args_message    = apply_filters( 'ld_group_email_users_personalize_message', $mail_args['message'], $user_data, $group_email_data );
			$ulgm_gdpr_compliance = apply_filters( 'ulgm_gdpr_is_group_leader_allowed', true, wp_get_current_user(), (int) $group_email_data['group_id'], $user_data, 'email-users' );

			if ( ! $ulgm_gdpr_compliance ) {
				$mail_errors[] = $email_address;
			} else {
				$send_mail = apply_filters( 'ulgm_maybe_send_group_email', true, $email_address, $mail_args_subject );


Scroll to Top