Group Administration
-
I would like to see a feature where the site admin is the only one with the authority to create groups. All users can join, etc. But not create. Is this possible or in the works?
-
You can use the new function bp_core_remove_subnav item
and create the new subnav
bp_core_add_subnav_item( $bp->groups->slug, 'create', __('Create a Group', 'buddypress'), $groups_link, 'groups_screen_create_group', false, is_site_admin() );
Thanks for the reply, But both your suggestions seems to be removing just menu, if some goes directly to /groups/create he can still fill a form.
No, if you create the new sub_item with “is_site_admin()”
only site admin can create groups
I have done this by
1. If user is not is_site_admin() it calls remove_action
2. Added a new action to my own function, which basically is a copy of BuddyPress function except the code to add bp_core_add_subnav_item
Is it a good practice to avoid any hacking to the core? Please suggest.
Paste here your code
function bp_group_admin_only(){
global $bp, $current_blog;
global $group_obj, $is_single_group;
if (!is_site_admin()){
remove_action( 'wp', 'groups_setup_nav', 2 );
}
}
/* I am using the same function (groups_setup_nav) as BuddyPress to avoid
* any hacking to the original code
*/
function manoj_groups_setup_nav(){
if (!is_site_admin() ){
global $bp, $current_blog;
global $group_obj, $is_single_group;
if ( $group_id = BP_Groups_Group::group_exists($bp->current_action) ) {
/* This is a single group page. */
$is_single_group = true;
$group_obj = new BP_Groups_Group( $group_id );
/* Using "item" not "group" for generic support in other components. */
if ( is_site_admin() )
$bp->is_item_admin = 1;
else
$bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $group_obj->id );
/* If the user is not an admin, check if they are a moderator */
if ( !$bp->is_item_admin )
$bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $group_obj->id );
/* Is the logged in user a member of the group? */
$is_member = ( groups_is_user_member( $bp->loggedin_user->id, $group_obj->id ) ) ? true : false;
/* Should this group be visible to the logged in user? */
$is_visible = ( 'public' == $group_obj->status || $is_member ) ? true : false;
}
/* Add 'Groups' to the main navigation */
bp_core_add_nav_item( __('Groups', 'buddypress'), $bp->groups->slug );
if ( $bp->displayed_user->id )
bp_core_add_nav_default( $bp->groups->slug, 'groups_screen_my_groups', 'my-groups' );
$groups_link = $bp->loggedin_user->domain . $bp->groups->slug . '/';
/* Add the subnav items to the groups nav item */
bp_core_add_subnav_item( $bp->groups->slug, 'my-groups', __('My Groups', 'buddypress'), $groups_link, 'groups_screen_my_groups', 'my-groups-list' );
//bp_core_add_subnav_item( $bp->groups->slug, 'create', __('Create a Group', 'buddypress'), $groups_link, 'groups_screen_create_group', false, bp_is_home() );
bp_core_add_subnav_item( $bp->groups->slug, 'invites', __('Invites', 'buddypress'), $groups_link, 'groups_screen_group_invites', false, bp_is_home() );
if ( $bp->current_component == $bp->groups->slug ) {
if ( bp_is_home() && !$is_single_group ) {
$bp->bp_options_title = __('My Groups', 'buddypress');
} else if ( !bp_is_home() && !$is_single_group ) {
$bp->bp_options_avatar = bp_core_get_avatar( $bp->displayed_user->id, 1 );
$bp->bp_options_title = $bp->displayed_user->fullname;
} else if ( $is_single_group ) {
// We are viewing a single group, so set up the
// group navigation menu using the $group_obj global.
/* When in a single group, the first action is bumped down one because of the
group name, so we need to adjust this and set the group name to current_item. */
$bp->current_item = $bp->current_action;
$bp->current_action = $bp->action_variables[0];
array_shift($bp->action_variables);
$bp->bp_options_title = bp_create_excerpt( $group_obj->name, 1 );
$bp->bp_options_avatar = '<img src="' . $group_obj->avatar_thumb . '" alt="Group Avatar Thumbnail" />';
$group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $group_obj->slug . '/';
// If this is a private or hidden group, does the user have access?
if ( 'private' == $group_obj->status || 'hidden' == $group_obj->status ) {
if ( groups_is_user_member( $bp->loggedin_user->id, $group_obj->id ) && is_user_logged_in() )
$has_access = true;
else
$has_access = false;
} else {
$has_access = true;
}
// Reset the existing subnav items
bp_core_reset_subnav_items($bp->groups->slug);
// bp_core_add_nav_default( $bp->groups->slug, 'groups_screen_group_home', 'home' );
bp_core_add_subnav_item( $bp->groups->slug, 'home', __('Home', 'buddypress'), $group_link, 'groups_screen_group_home', 'group-home' );
// If the user is a group mod or more, then show the group admin nav item */
if ( $bp->is_item_mod || $bp->is_item_admin )
bp_core_add_subnav_item( $bp->groups->slug, 'admin', __('Admin', 'buddypress'), $group_link , 'groups_screen_group_admin', 'group-admin', ( $bp->is_item_admin + (int)$bp->is_item_mod ) );
// If this is a private group, and the user is not a member, show a "Request Membership" nav item.
if ( !$has_access && !groups_check_for_membership_request( $bp->loggedin_user->id, $group_obj->id ) && $group_obj->status == 'private' )
bp_core_add_subnav_item( $bp->groups->slug, 'request-membership', __('Request Membership', 'buddypress'), $group_link , 'groups_screen_group_request_membership', 'request-membership' );
if ( $has_access && $group_obj->enable_forum && function_exists('bp_forums_setup') )
bp_core_add_subnav_item( $bp->groups->slug, 'forum', __('Forum', 'buddypress'), $group_link , 'groups_screen_group_forum', 'group-forum', $is_visible);
if ( $has_access && $group_obj->enable_wire && function_exists('bp_wire_install') )
bp_core_add_subnav_item( $bp->groups->slug, 'wire', __('Wire', 'buddypress'), $group_link, 'groups_screen_group_wire', 'group-wire', $is_visible );
if ( $has_access && $group_obj->enable_photos && function_exists('bp_gallery_install') )
bp_core_add_subnav_item( $bp->groups->slug, 'photos', __('Photos', 'buddypress'), $group_link, 'groups_screen_group_photos', 'group-photos', $is_visible );
if ( $has_access )
bp_core_add_subnav_item( $bp->groups->slug, 'members', __('Members', 'buddypress'), $group_link, 'groups_screen_group_members', 'group-members', $is_visible );
if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $group_obj->id ) ) {
if ( function_exists('friends_install') )
bp_core_add_subnav_item( $bp->groups->slug, 'send-invites', __('Send Invites', 'buddypress'), $group_link, 'groups_screen_group_invite', 'group-invite', $is_member );
bp_core_add_subnav_item( $bp->groups->slug, 'leave-group', __('Leave Group', 'buddypress'), $group_link, 'groups_screen_group_leave', 'group-leave', $is_member );
}
}
}
}
}
add_action( 'wp', 'bp_group_admin_only',1);
add_action( 'wp', 'manoj_groups_setup_nav',2);That’s really simpler you think
I’ve a coffee break now, i’ll write some lines
Any Suggestions?
Can someone who knows more than me (in otherwords, anything at all) abou creating this function let me know:
– which file to edit (in which directory)
– which files to create (and in which directory)
– what code to use in both cases
I am using WP 9.2, as opposed to WPMU…
I found the answer with:
https://buddypress.org/forums/topic/how-do-i-disable-members-from-creating-groups
This is how it goes.
You ned to edit your child template.
Using the “BuddyPress Template Pack” plugin, or using the instruction in http://irishpinkadoptions.com/wp-content/themes/dkret3/readme.html#filters you have created a child theme.
You can find the files in: /site/wp-content/themes/<your theme>/groups/
You can edit 2 files:
– index.php to remove the button to create group
– create.php so peopel cannot just go and use the goup/create shortcut.
The idea is that you need to be logged in and “&& current_user_can(‘level_10’)” to be allowed to do soemthimg.
INDEX.PHP before the modif:
<form action="" method="post" id="groups-directory-form" class="dir-form">
<h3><?php _e( 'Groups Directory', 'buddypress' ) ?><?php if ( is_user_logged_in()) : ?> Â <a class="button" href="<?php echo bp_get_root_domain() . '/' . BP_GROUPS_SLUG . '/create/' ?>"><?php _e( 'Create a Group', 'buddypress' ) ?></a><?php endif; ?></h3>INDEX.PHP after the modif:
<form action="" method="post" id="groups-directory-form" class="dir-form">
<h3><?php _e( 'Groups Directory', 'buddypress' ) ?><?php if ( is_user_logged_in() && current_user_can('level_10')) : ?> Â <a class="button" href="<?php echo bp_get_root_domain() . '/' . BP_GROUPS_SLUG . '/create/' ?>"><?php _e( 'Create a Group', 'buddypress' ) ?></a><?php endif; ?></h3>CREATE.PHP before
<?php if ( is_user_logged_in() ) : ?>
<form action="<?php bp_group_creation_form_action() ?>" method="post" id="create-group-form" class="standard-form" enctype="multipart/form-data">
......
...very long form...
......
<?php do_action( 'bp_after_create_group' ) ?>
</form>
<?php endif; ?>CREATE.PHP after
<?php if ( is_user_logged_in() && current_user_can('level_10')) : ?>
<form action="<?php bp_group_creation_form_action() ?>" method="post" id="create-group-form" class="standard-form" enctype="multipart/form-data">
......
...very long form...
......
<?php do_action( 'bp_after_create_group' ) ?>
</form>
<?php endif; ?>
<?php if ( is_user_logged_in() && !current_user_can('level_10')) : ?>
<?php echo '<h3>You do not have authority. And it is not nice to trying to break into the code... it makes the code cry.<h3>'; ?>
<?php endif; ?>So Nicola, did you ever create the plugin?
I would like to see the ability to create Groups in the Admin site and have the users automatically added to the group based upon a response to a question in their account creation screen. Then the users would be able to create sub groups and have control over those sub groups.
It would also be nice to be able limit access to categories based upon the Main group the subscriber is assigned to.
Try Boone’s BP Group Management Plugin:
https://wordpress.org/extend/plugins/bp-group-management/Thanks r-a-y, but from the description Boone’s sounds too basic for what I need to do. Have you used it? Does it allow you to automatically assign users to a group based upon a question selection when they create their profile and login?
- The topic ‘Group Administration’ is closed to new replies.