Action uncanny-learndash-groups

ulgm_group_user_removed

Fires when a user is removed from a group, passing the user and group IDs.

add_action( 'ulgm_group_user_removed', $callback, 10, 2 );

Description

Fired after a user is removed from a LearnDash group. Developers can use this hook to perform custom actions, such as revoking specific course access or updating user metadata. It passes the removed user's ID and the group's ID.


Usage

add_action( 'ulgm_group_user_removed', 'your_function_name', 10, 2 );

Parameters

$user_id (mixed)
The user ID of the user who has been removed from a group.
$group_id (mixed)
The user ID of the user who was removed from a group.

Examples

<?php
/**
 * Example function to hook into ulgm_group_user_removed.
 *
 * This function logs the removal of a user from a group and potentially performs other actions.
 *
 * @param int $user_id The ID of the user who was removed.
 * @param int $group_id The ID of the group from which the user was removed.
 */
function my_custom_user_group_removal_handler( $user_id, $group_id ) {
    // Log the user removal event for debugging or auditing purposes.
    error_log( sprintf( 'User ID %d has been removed from Group ID %d.', $user_id, $group_id ) );

    // Example: If the removed user was a specific type of member (e.g., an administrator of the group),
    // you might want to reassign responsibilities or notify someone.
    // This is a hypothetical scenario and would depend on your specific plugin's functionality.
    $user_role_in_group = get_user_meta( $user_id, 'ulgm_group_role_' . $group_id, true );

    if ( 'group_admin' === $user_role_in_group ) {
        error_log( sprintf( 'Group admin (User ID %d) removed from Group ID %d. Consider reassigning admin roles.', $user_id, $group_id ) );
        // Here you might trigger another action to find a new admin or notify the site owner.
    }

    // Example: If you have specific cleanup tasks for users removed from groups,
    // such as revoking certain permissions or sending a notification email.
    // This is a placeholder for potential further actions.
    // For instance, you might want to check if this was the last group the user was in
    // and if that means they should lose access to specific content.
    // $user_groups = ulgm_get_user_groups( $user_id ); // Hypothetical function
    // if ( empty( $user_groups ) ) {
    //     // User is no longer in any groups, perform site-wide cleanup if necessary.
    //     my_user_lost_all_group_access_cleanup( $user_id );
    // }
}

// Hook the function to the ulgm_group_user_removed action.
// The third parameter '2' indicates that this callback function accepts 2 arguments.
add_action( 'ulgm_group_user_removed', 'my_custom_user_group_removal_handler', 10, 2 );
?>

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

}

					// set all
					//learndash_set_users_group_ids( $user_id, $current_user_groups );
					ld_update_group_access( $user_id, $group_id, true );
					// remove the group membership role if no longer a member of any groups
					do_action( 'uo-groups-role-cleanup', $user_id ); //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
					do_action( 'ulgm_group_user_removed', $user_id, (int) $group_id );
				}

				$data['message'] = _n(
					'User is removed.',
					'Users have been removed.',
					count( $users ),
					'uncanny-learndash-groups'


Scroll to Top