Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 25th, 2013  |  syntax: PHP  |  size: 1.91 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function etivite_bp_group_adminmod_member_before_save( $member ) {
  2.         global $wpdb, $bp;
  3.        
  4.         //no data - no bother
  5.         $data = get_option( 'etivite_bp_group_adminmod' );
  6.         if ( !$data || empty( $data ) || !$data['group']['id'] )
  7.                 return;
  8.                
  9.         $is_member = groups_is_user_member( $member->user_id, $data['group']['id'] );
  10.  
  11.         //holy infinity and beyond...
  12.         remove_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
  13.  
  14.         //check if member is_mod/admin and add to group if not a member
  15.         if ( ( $member->is_mod || $member->is_admin ) && !$is_member ) {
  16.                 $new_member = new BP_Groups_Member( $member->user_id, $data['group']['id'] );
  17.                 $new_member->is_confirmed  = 1;
  18.                 $new_member->inviter_id    = 0;
  19.                 $new_member->invite_sent   = 0;
  20.                 $new_member->is_admin      = 0;
  21.                 $new_member->user_title    = '';
  22.                 $new_member->date_modified = bp_core_current_time();
  23.                 $new_member->save();
  24.                 groups_update_groupmeta( $data['group']['id'], 'total_member_count', (int) groups_get_groupmeta( $data['group']['id'], 'total_member_count') + 1 );
  25.         }
  26.        
  27.         //check if member is admin/mod of any groups. If not, remove from adminmod group - boone!
  28.         $is_admin_or_mod_anywhere_else = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$bp->groups->table_name_members} WHERE user_id = %d AND ( is_admin = 1 OR is_mod = 1 ) AND group_id != %d", $member->user_id, $member->group_id ) );
  29.  
  30.         if ( !$is_admin_or_mod_anywhere_else && !$member->is_admin && !$member->is_mod ) {
  31.                 $remove_member = new BP_Groups_Member( $member->user_id, $data['group']['id'] );
  32.                 $remove_member->remove();
  33.                 groups_update_groupmeta( $data['group']['id'], 'total_member_count', (int) groups_get_groupmeta( $data['group']['id'], 'total_member_count') - 1 );
  34.         }
  35.        
  36.         add_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
  37.  
  38. }
  39. add_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );