Created
August 29, 2019 14:10
-
-
Save raviousprime/ea52f4b1ebb531731387a70eb95e91c8 to your computer and use it in GitHub Desktop.
Bulk join user of certain role to BuddyPress group when created
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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