Filter uncanny-toolkit-pro

uo_import_users_convert_mail_text

Filters the text used for email notifications during user import, allowing customization of content.

add_filter( 'uo_import_users_convert_mail_text', $callback, 10, 4 );

Description

Filters the text used in user import emails. Developers can modify mail content, like personalization tags, before emails are sent. The hook provides access to the user's email, the original text, and arguments used for email construction. Use this to customize user import notification messages.


Usage

add_filter( 'uo_import_users_convert_mail_text', 'your_function_name', 10, 4 );

Parameters

$text (mixed)
This parameter contains the original, un-processed email text that will be potentially modified by the filter.
$user_email (mixed)
This parameter contains the original email text to be potentially modified.
$text (mixed)
This parameter contains the raw text that will be converted for email content.
$email_text_args (mixed)
This parameter appears to be a duplicate of the first `$text` parameter and is intended to contain the text content of an email that needs to be converted or processed.

Return Value

The filtered value.


Examples

add_filter( 'uo_import_users_convert_mail_text', 'my_custom_user_import_mail_text', 10, 4 );

/**
 * Customize the email text during user import.
 *
 * This function allows you to modify the email content sent to newly imported users.
 * For example, you could add a custom greeting or append specific instructions.
 *
 * @param string $text The original email text.
 * @param string $user_email The email address of the user being imported.
 * @param string $original_text The original email text before any replacements. This parameter seems to be a duplicate of $text based on the source context.
 * @param array $email_text_args An array of arguments used to generate the email text.
 * @return string The modified email text.
 */
function my_custom_user_import_mail_text( $text, $user_email, $original_text, $email_text_args ) {

	// Let's add a custom line to the email before the existing content.
	$custom_greeting = "nnWelcome aboard! We're excited to have you join our community.nn";

	// We can also append some specific instructions related to a certain user role,
	// assuming we can infer it from $email_text_args if it contains such information.
	// For this example, let's just add a general note.
	$custom_note = "Please remember to update your profile information after logging in.n";

	// Combine the custom content with the original text.
	// We'll insert the greeting at the beginning and the note at the end.
	$modified_text = $custom_greeting . $text . $custom_note;

	// If you wanted to modify a specific placeholder, you could do something like this:
	// $modified_text = str_replace( '%Login URL%', 'https://your-custom-login.com', $modified_text );

	return $modified_text;
}

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/import-learndash-users-from-csv.php:1642

private static function convert_mail_text( $user_email, $text, $password = 'Password', $email_text_args = array() ) {

		$wp_user      = get_user_by( 'email', $user_email );
		$user_id      = $wp_user->ID;
		$user_email   = $wp_user->user_email;
		$user_name    = $wp_user->user_login;
		$first_name   = $wp_user->first_name;
		$last_name    = $wp_user->last_name;
		$display_name = $wp_user->data->display_name;

		$text = str_replace( '%Site URL%', get_home_url(), $text );
		$text = str_replace( '%Login URL%', wp_login_url(), $text );
		$text = str_replace( '%Email%', $user_email, $text );
		$text = str_replace( '%Username%', $user_name, $text );
		$text = str_replace( '%First Name%', $first_name, $text );
		$text = str_replace( '%Last Name%', $last_name, $text );
		$text = str_replace( '%Password%', $password, $text );
		$text = str_replace( '%Reset Password Link%', self::generate_reset_token( $user_id ), $text );
		$text = str_replace( '%Password Reset URL%', self::generate_reset_url( $user_id ), $text );
		$text = str_replace( '%Display Name%', $display_name, $text );
		if ( self::is_learndash_active() ) {
			// Courses
			$user_courses = array();
			foreach ( ld_get_mycourses( $user_id ) as $course_id ) {
				$course         = get_post( $course_id );
				$user_courses[] = $course->post_title;
			}
			$user_courses = implode( ', ', $user_courses );

			$text = str_replace( '%LD Courses%', $user_courses, $text );

			// Groups
			$user_groups = array();
			foreach ( learndash_get_users_group_ids( $user_id ) as $group_id ) {
				$group         = get_post( $group_id );
				$user_groups[] = $group->post_title;
			}
			$user_groups = implode( ', ', $user_groups );

			$text = str_replace( '%LD Groups%', $user_groups, $text );
		} else {
			$text = str_replace( '%LD Groups%', '', $text );
			$text = str_replace( '%LD Courses%', '', $text );
		}
		// Esc Chars
		$text = str_replace( '"', '"', $text );
		$text = str_replace( "'", "'", $text );

		return apply_filters( 'uo_import_users_convert_mail_text', $text, $user_email, $text, $email_text_args );
	}


Scroll to Top