bp_ld_sync/learndash_group_user_removed
Fires when a user is removed from a LearnDash group synced with BuddyPress.
add_action( 'bp_ld_sync/learndash_group_user_removed', $callback, 10, 2 );
Description
Fires after a user is removed from a BuddyBoss Group that is synced with LearnDash. Developers can use this action to perform custom actions, such as revoking LearnDash course access, sending notifications, or logging the removal. The hook passes the group ID and user ID as arguments.
Usage
add_action( 'bp_ld_sync/learndash_group_user_removed', 'your_function_name', 10, 2 );
Parameters
-
$group_id(mixed) - The ID of the LearnDash group from which the user was removed.
-
$user_id(mixed) - The ID of the LearnDash group from which the user was removed.
Examples
/**
* Example of how to hook into the 'bp_ld_sync/learndash_group_user_removed' action.
*
* This function will be executed whenever a user is removed from a BuddyBoss Group
* that is synced with a LearnDash Group.
*
* @param int $group_id The ID of the BuddyBoss Group.
* @param int $user_id The ID of the user removed from the group.
*/
function my_learndash_group_user_removed_handler( $group_id, $user_id ) {
// Check if LearnDash is active and the group is associated with a LearnDash course.
if ( class_exists( 'SFWD_LMS' ) && function_exists( 'learndash_is_group_leader_for_group' ) ) {
// Attempt to get the associated LearnDash Group ID.
// You would typically have a mechanism to store this mapping, e.g., in post meta.
// For this example, let's assume a custom function or meta lookup.
$learndash_group_id = get_post_meta( $group_id, '_learndash_group_id', true );
if ( ! empty( $learndash_group_id ) ) {
// Get the LearnDash Group object.
$learndash_group = learndash_get_group( $learndash_group_id );
if ( $learndash_group ) {
// Remove the user from the LearnDash Group.
// Note: This is a simplified example. In a real-world scenario,
// you might want to check if the user has completed any courses
// within the LearnDash Group or handle other specific logic.
learndash_remove_user_from_group( $user_id, $learndash_group_id );
// Optionally, trigger other actions, like logging or notifications.
error_log( "User {$user_id} removed from BuddyBoss Group {$group_id} (LearnDash Group {$learndash_group_id})." );
}
}
}
}
add_action( 'bp_ld_sync/learndash_group_user_removed', 'my_learndash_group_user_removed_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/buddyboss/buddy-boss-sync.php:122
public function user_removed_from_group( $user_id, $group_id ) {
do_action( 'bp_ld_sync/learndash_group_user_removed', $group_id, $user_id );
}