Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Buddypress allow site admins to join any group

By: a guest on Aug 12th, 2010  |  syntax: PHP  |  size: 1.42 KB  |  views: 63  |  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.  
  2. //
  3. // creates a new join button to allow the site admin to join any group
  4. //
  5.  
  6. function scg_site_admin_group_join_button() {
  7.         global $bp, $groups_template;
  8.  
  9.         $group =& $groups_template->group;
  10.  
  11.         if ( !$bp->loggedin_user->is_site_admin )
  12.                 return false;
  13.  
  14.         if ( !$group->is_member && $group->status != 'public' )
  15.                 echo '<div class="generic-button">Site Admin can <a class="join-group" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'admin-join', 'admin_groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a></div>';
  16.  
  17. }
  18. add_action( 'bp_group_header_meta', 'scg_site_admin_group_join_button', 1);
  19.  
  20. // catch the join request from the button added in function above
  21. function scg_admin_groups_action_join_group() {
  22.         global $bp;
  23.  
  24.         if ( !$bp->loggedin_user->is_site_admin || !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != 'admin-join' )
  25.                 return false;
  26.  
  27.         // Nonce check
  28.         if ( !check_admin_referer( 'admin_groups_join_group' ) )
  29.                 return false;
  30.  
  31.         // User wants to join any group
  32.         if ( !groups_join_group( $bp->groups->current_group->id ) )
  33.                 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' );
  34.         else
  35.                 bp_core_add_message( __( 'You joined the group!', 'buddypress' ) );
  36.  
  37.         bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
  38. }
  39. add_action( 'wp', 'scg_admin_groups_action_join_group', 3 );