ulgm_do_not_send_existing_user_email
Filters whether to send emails to existing users when they are added to a group.
add_filter( 'ulgm_do_not_send_existing_user_email', $callback, 10, 4 );
Description
Filters whether an email notification should be sent to an existing user when they are added to a group. Developers can return `true` to prevent the email from being sent, or `false` to allow it. This hook is applied after a user is confirmed to exist and before the email sending logic.
Usage
add_filter( 'ulgm_do_not_send_existing_user_email', 'your_function_name', 10, 4 );
Parameters
-
$do_not_send_emails(mixed) - This parameter determines whether emails should be suppressed for an existing user being added to a group.
-
$user_data(mixed) - This parameter is a boolean value that determines whether or not to send an email notification to an existing user who has been added to a group.
-
$group_id(mixed) - This parameter contains an array of data related to the user being added to a group.
-
$order_id(mixed) - This parameter holds the ID of the group the user is being added to.
Return Value
The filtered value.
Examples
/**
* Prevent sending an email to an existing user when they are added to a group.
*
* This filter allows developers to conditionally prevent the default email notification
* from being sent to users who already exist on the site and are being added to a group.
* For example, you might want to suppress this email if the user has opted out of
* all notifications or if a different notification process is handling this scenario.
*
* @param bool $do_not_send_emails Whether to prevent sending emails. Default is false.
* @param array $user_data The data of the user being added to the group.
* @param int $group_id The ID of the group the user is being added to.
* @param int $order_id The ID of the order associated with the group membership.
*
* @return bool True to prevent sending emails, false otherwise.
*/
add_filter( 'ulgm_do_not_send_existing_user_email', function( $do_not_send_emails, $user_data, $group_id, $order_id ) {
// Example: Prevent sending emails if the user has a specific meta key set.
// This could represent a user who has opted out of all group notifications.
if ( isset( $user_data['ID'] ) ) {
$user_id = $user_data['ID'];
if ( get_user_meta( $user_id, 'opt_out_of_group_notifications', true ) === 'yes' ) {
return true; // Prevent sending email
}
}
// Example: Prevent sending emails for a specific group.
// For instance, if a particular group is for internal use and doesn't require user notification.
$specific_group_to_suppress = 123; // Replace with the actual group ID
if ( $group_id === $specific_group_to_suppress ) {
return true; // Prevent sending email for this group
}
// If none of the above conditions are met, return the original value.
// This ensures that the default behavior (sending emails) is maintained unless explicitly overridden.
return $do_not_send_emails;
}, 10, 4 );
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:768
if ( $is_api ) {
wp_send_json_error( $data );
}
}
}
do_action( 'ulgm_existing_group_user_added', $user_data, $group_id, $order_id );
$do_not_send_emails = apply_filters( 'ulgm_do_not_send_existing_user_email', $do_not_send_emails, $user_data, $group_id, $order_id );
if ( $do_not_send_emails ) {
$data['message'] = __( 'The specified user was already registered on the site and has been automatically added to this group.', 'uncanny-learndash-groups' );
if ( $counter ) {
return array(