ulgm_group_leader_removed
Fires when a user is removed as a leader from a group, passing the user and group IDs.
add_action( 'ulgm_group_leader_removed', $callback, 10, 2 );
Description
Fires when a user is removed as a leader from a group. Developers can use this hook to perform custom actions after a group leader is unassigned, such as revoking specific permissions or updating related data. It passes the removed leader's user ID and the group ID.
Usage
add_action( 'ulgm_group_leader_removed', 'your_function_name', 10, 2 );
Parameters
-
$user_id(mixed) - The ID of the user who was removed as a group leader.
-
$group_id(mixed) - This parameter contains the user ID of the group leader who has been removed.
Examples
/**
* Hook into ulgm_group_leader_removed to perform custom actions when a group leader is removed.
*
* For example, you might want to:
* - Log the removal for auditing purposes.
* - Send a notification to the user or an administrator.
* - Clean up any custom data associated with the user's leadership role in that group.
*
* @param int $user_id The ID of the user who was removed as a group leader.
* @param int $group_id The ID of the group from which the user was removed as a leader.
*/
function my_custom_group_leader_removed_action( $user_id, $group_id ) {
// Example: Log the removal event for auditing.
$user_info = get_userdata( $user_id );
$group_name = get_post_meta( $group_id, 'group_name', true ); // Assuming 'group_name' is a meta key for group name.
if ( $user_info && $group_name ) {
$log_message = sprintf(
'Group leader removed: User "%s" (ID: %d) was removed as a leader from group "%s" (ID: %d).',
$user_info->user_login,
$user_id,
$group_name,
$group_id
);
error_log( $log_message ); // Log to the PHP error log.
}
// Example: Send a notification to the user (if the group plugin doesn't handle this).
// You would typically use a WordPress notification system or email function here.
// For simplicity, we'll just show a placeholder comment.
// wp_mail( $user_info->user_email, 'You are no longer a group leader', 'You have been removed as a leader...' );
// Example: Perform custom cleanup if necessary.
// delete_user_meta( $user_id, 'custom_group_leader_setting_' . $group_id );
}
add_action( 'ulgm_group_leader_removed', 'my_custom_group_leader_removed_action', 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:1434
$data['error'] = 'invalid-group-id';
wp_send_json_error( $data );
}
$group_id = absint( $request->get_param( 'group-id' ) );
foreach ( $users as $user_id ) {
ld_update_leader_group_access( $user_id, $group_id, true );
do_action( 'ulgm_group_leader_removed', $user_id, (int) $group_id );
if ( has_action( 'uo_groups_role_cleanup' ) || has_action( 'uo-groups-role-cleanup' ) ) {
do_action_deprecated(
'uo-groups-role-cleanup',
array( $user_id ),
'4.4.1',
'uo_groups_role_cleanup'
); // remove the group leader role if no longer a member of any groups