
Buddypress allow site admins to join any group
By: a guest on
Aug 12th, 2010 | syntax:
PHP | size: 1.42 KB | hits: 59 | expires: Never
//
// creates a new join button to allow the site admin to join any group
//
function scg_site_admin_group_join_button() {
global $bp, $groups_template;
$group =& $groups_template->group;
if ( !$bp->loggedin_user->is_site_admin )
return false;
if ( !$group->is_member && $group->status != 'public' )
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>';
}
add_action( 'bp_group_header_meta', 'scg_site_admin_group_join_button', 1);
// catch the join request from the button added in function above
function scg_admin_groups_action_join_group() {
global $bp;
if ( !$bp->loggedin_user->is_site_admin || !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != 'admin-join' )
return false;
// Nonce check
if ( !check_admin_referer( 'admin_groups_join_group' ) )
return false;
// User wants to join any group
if ( !groups_join_group( $bp->groups->current_group->id ) )
bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' );
else
bp_core_add_message( __( 'You joined the group!', 'buddypress' ) );
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
}
add_action( 'wp', 'scg_admin_groups_action_join_group', 3 );