Filter uncanny-toolkit-pro

uo_ld_expire_group_email_subject

Filters the subject line for group expiration emails sent to users.

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

Description

Filters the subject line for emails sent when a LearnDash group expires. Developers can modify the default subject, $email_title, using the $user and $group_id parameters to personalize or change the email's purpose entirely.


Usage

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

Parameters

$email_title (mixed)
This parameter contains the email subject title, which can be filtered and modified.
$user (mixed)
This parameter is the title of the email that will be sent.
$group_id (mixed)
This parameter represents the user object for whom the group expiration email subject is being generated.

Return Value

The filtered value.


Examples

/**
 * Modify the email subject for LearnDash group expiration notifications.
 *
 * This function demonstrates how to use the 'uo_ld_expire_group_email_subject' filter
 * to customize the subject line of emails sent when a LearnDash group expires.
 *
 * @param string $email_title The original email subject.
 * @param WP_User $user The user object for the recipient.
 * @param int $group_id The ID of the expired LearnDash group.
 * @return string The modified email subject.
 */
add_filter( 'uo_ld_expire_group_email_subject', function( $email_title, $user, $group_id ) {

	// Get the group name.
	$group_name = get_the_title( $group_id );

	// Construct a more personalized subject line.
	$modified_subject = sprintf(
		'%s - Your access to "%s" has expired.',
		get_bloginfo( 'name' ), // Site name for context.
		$group_name
	);

	// Optionally, add user-specific information if available or relevant.
	// For example, if we wanted to include the user's display name.
	// $modified_subject = sprintf(
	// 	'%s - %s, your access to "%s" has expired.',
	// 	get_bloginfo( 'name' ),
	// 	$user->display_name,
	// 	$group_name
	// );

	// Return the modified subject.
	return $modified_subject;

}, 10, 3 ); // Priority 10, accepting 3 arguments: $email_title, $user, $group_id

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/learn-dash-group-expiration.php:806

public static function email_group( $group_id ) {
		if ( 'yes' === self::$send_email && function_exists( 'learndash_group_enrolled_courses' ) ) {
			if ( 'on' === self::$send_email_group_leader_only ) {
				$user_ids = learndash_get_groups_administrator_ids( $group_id );
				$user_ids = array_unique( $user_ids );
			} else {
				$user_ids = array_merge( learndash_get_groups_user_ids( $group_id ), learndash_get_groups_administrator_ids( $group_id ) );
				$user_ids = array_unique( $user_ids );
			}
			if ( $user_ids ) {

				$email_title     = self::get_email_title( $group_id );
				$email_body      = self::get_email_body( $group_id );
				$expiration_date = get_post_meta( $group_id, 'uo-expiration-date', true );
				$group_name      = get_the_title( $group_id );

				$email_body = str_ireplace(
					array(
						'%LearnDash Group Name%',
						'%expiration date%',
					),
					array(
						$group_name,
						$expiration_date,
					),
					$email_body
				);

				$headers   = array();
				$headers[] = 'Content-type: text/html; charset=UTF-8';
				$headers[] = 'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>';
				$headers   = apply_filters( 'uo_ld_expire_group_email_headers', $headers );
				foreach ( $user_ids as $user_id ) {
					$group_progress = learndash_get_user_group_progress( $group_id, $user_id );
					if ( true === apply_filters( 'uo_ld_expire_group_do_not_send_email_to_user', false, $user_id, $group_id, $group_progress ) ) {
						continue;
					}
					$user      = get_userdata( $user_id );
					$email     = $user->user_email;
					$user_name = $user->display_name;

					$message = str_ireplace( '%display name%', $user_name, $email_body );
					$message = nl2br( stripcslashes( $message ) );
					$message = wpautop( $message );
					$message = apply_filters( 'uo_ld_expire_group_email_message', $message, $user, $group_id );
					$sub     = apply_filters( 'uo_ld_expire_group_email_subject', $email_title, $user, $group_id );

					wp_mail( $email, $sub, $message, $headers );
				}
			}
		}

		update_post_meta( $group_id, 'uo-email-group-sent', current_time( get_option( 'date_format' ) . ' H:i:s' ) );
		wp_clear_scheduled_hook( 'uo-email-group', array( $group_id ) );
	}


Scroll to Top