Action
uncanny-automator-pro
automator_groups_remove_member
Fires when a member is removed from a BuddyPress group, passing the group and user objects.
add_action( 'automator_groups_remove_member', $callback, 10, 2 );
Description
Fires when a user is removed from a BuddyPress group. Developers can use this hook to trigger custom automations or log when a user leaves a group, passing the group ID and user ID as parameters. This hook fires after the user has been removed from the group.
Usage
add_action( 'automator_groups_remove_member', 'your_function_name', 10, 2 );
Parameters
-
$group(mixed) - This parameter represents the group from which the member is being removed.
-
$user(mixed) - This parameter contains information about the group from which a member is being removed.
Examples
// Hook into the 'automator_groups_remove_member' action to record the removal event.
// This allows other plugins or themes to react when a user is removed from a group by Uncanny Automator.
add_action( 'automator_groups_remove_member', 'my_automator_handle_user_group_removal', 10, 2 );
/**
* Handles the event of a user being removed from a group by Uncanny Automator.
*
* @param int $group_id The ID of the group the user was removed from.
* @param int $user_id The ID of the user who was removed.
*/
function my_automator_handle_user_group_removal( $group_id, $user_id ) {
// In a real-world scenario, you might want to log this event,
// send a notification, or perform other actions.
// For this example, we'll just log it to the debug log.
// Ensure the user and group IDs are valid integers before proceeding.
if ( ! is_numeric( $group_id ) || ! is_numeric( $user_id ) ) {
error_log( 'Invalid group or user ID passed to my_automator_handle_user_group_removal.' );
return;
}
$user = get_userdata( $user_id );
$group = groups_get_group( array( 'group_id' => $group_id ) );
if ( ! $user || ! $group ) {
error_log( 'Could not retrieve user or group data for removal event.' );
return;
}
// Example: Log the event to WordPress debug log
if ( WP_DEBUG === true ) {
error_log( sprintf(
'User "%s" (ID: %d) was removed from group "%s" (ID: %d) by Uncanny Automator.',
$user->user_login,
$user_id,
$group->name,
$group_id
) );
}
// You could also add additional logic here, such as:
// - Updating user meta
// - Triggering other custom actions
// - Sending an email notification to an administrator
}
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
uncanny-automator-pro/src/integrations/buddypress/triggers/bp-user-removed-from-group.php:192
public function maybe_trigger_automator_groups_remove_member( $user, $member, $group, $response, $request ) {
// Bail if either action has already been triggered.
if ( did_action( 'automator_groups_remove_member' ) || did_action( 'groups_remove_member' ) ) {
return;
}
do_action( 'automator_groups_remove_member', $group->id, $user->ID );
}