Created
          October 27, 2014 07:46 
        
      - 
      
- 
        Save qutek/9cc81fab92ed0a0e4a52 to your computer and use it in GitHub Desktop. 
    [Wordpress] [Buddypress] Batch add user to buddypress group
  
        
  
    
      This file contains hidden or 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 | |
| /** | |
| * Batch Add user to buddypress group | |
| */ | |
| add_action('load-users.php',function() { | |
| if(isset($_POST['action']) && ($_POST['action'] == 'groupadd') && isset($_POST['bp_gid']) && isset($_POST['allusers'])) { | |
| // print_r($_POST); exit(); | |
| $group_id = $_POST['bp_gid']; | |
| $users = $_POST['allusers']; | |
| foreach ($users as $user_id) { | |
| groups_accept_invite( $user_id, $group_id ); | |
| } | |
| } | |
| //Add some Javascript to handle the form submission | |
| add_action('admin_footer',function(){ ?> | |
| <script> | |
| jQuery("select[name='action']").append(jQuery('<option value="groupadd">Add to Group</option>')); | |
| jQuery("#doaction").click(function(e){ | |
| if(jQuery("select[name='action'] :selected").val()=="groupadd") { | |
| e.preventDefault(); | |
| gid=prompt("Please enter a BuddyPres Group ID","1"); | |
| jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit(); | |
| } | |
| }); | |
| </script> | |
| <?php | |
| }); | |
| }); | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment