Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bulk join user of certain role to BuddyPress group when created
<?php
add_action( 'groups_create_group', function( $group_id ) {
// Get users of certain roles.
$user_ids = get_users(
array(
'role' => array( 'subscriber' ),
'fields' => 'ID',
)
);
if ( empty( $user_ids ) ) {
return;
}
foreach ( $user_ids as $user_id ) {
// Add them to group.
groups_join_group( $group_id, $user_id );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.