Filter uncanny-learndash-groups

ulgm_do_not_send_new_user_email

Filters whether to prevent sending new user emails for specific users, user groups, or orders.

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

Description

Allows developers to conditionally prevent new user notification emails from being sent after they are added to a group. By returning `true` from this filter, you can bypass the default email sending logic, useful for specific integration scenarios or bulk operations where manual notification is preferred.


Usage

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

Parameters

$do_not_send_emails (mixed)
This parameter is a boolean value that indicates whether new user notification emails should be suppressed.
$user_data (mixed)
This parameter determines whether to prevent the sending of a new user email notification.
$group_id (mixed)
This parameter contains the data associated with the user who is being invited to a group.
$order_id (mixed)
This parameter holds the ID of the group to which the user is being added.

Return Value

The filtered value.


Examples

/**
 * Prevent sending welcome email to a specific user for a group.
 *
 * This filter allows developers to conditionally prevent the sending of a new user
 * welcome email based on user data, group ID, or order ID. For example, you might
 * want to skip the email if the user is already part of the group or if the order
 * is a renewal and the user has previously received a welcome email.
 *
 * @param bool   $do_not_send_emails Whether to prevent sending the email. Defaults to false.
 * @param array  $user_data        An array containing the user's data (e.g., ID, email).
 * @param int    $group_id         The ID of the Uncanny Groups group.
 * @param int|null $order_id       The ID of the order associated with the group purchase, or null.
 *
 * @return bool True to prevent sending the email, false otherwise.
 */
add_filter(
	'ulgm_do_not_send_new_user_email',
	function( $do_not_send_emails, $user_data, $group_id, $order_id ) {
		// Example: Prevent sending email if the user's email address is a specific domain
		// or if they are being added to a specific group that shouldn't send welcome emails.
		if ( isset( $user_data['email'] ) && str_ends_with( $user_data['email'], '@example.com' ) ) {
			return true; // Prevent sending email to @example.com addresses
		}

		// Example: Prevent sending email for a particular group ID.
		$specific_group_id_to_block_emails = 123; // Replace with your target group ID
		if ( $group_id === $specific_group_id_to_block_emails ) {
			return true; // Prevent sending email for this specific group
		}

		// Example: If an order ID is present and it's a renewal, maybe skip the email.
		// This would require more context about how renewals are identified (e.g., custom meta).
		// For demonstration, let's assume a 'is_renewal' flag in order meta.
		// if ( $order_id && 'yes' === get_post_meta( $order_id, '_is_renewal', true ) ) {
		//     return true;
		// }

		// If none of the conditions are met, return the default value.
		return $do_not_send_emails;
	},
	10, // Priority
	4  // Number of accepted arguments
);

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

// '' if success or use_error_code or if needed a custom
					),
				);
			}
		}

		do_action( 'ulgm_group_user_invited', $user_data, $group_id, $order_id );
		$do_not_send_emails = apply_filters( 'ulgm_do_not_send_new_user_email', $do_not_send_emails, $user_data, $group_id, $order_id );

		if ( $do_not_send_emails ) {

			if ( ! $counter ) {
				$data['message'] = __( 'User has been added.' . $password_info, 'uncanny-learndash-groups' );
				SharedFunctions::delete_transient( null, $group_id );
				if ( $is_api ) {


Scroll to Top