BP_Groups_Component::setup_nav( array $main_nav = array(), array $sub_nav = array() )
Set up component navigation.
Description
See also
- BP_Component::setup_nav(): for a description of arguments.
Parameters
- $main_nav
-
(Optional) See BP_Component::setup_nav() for description.
Default value: array()
- $sub_nav
-
(Optional) See BP_Component::setup_nav() for description.
Default value: array()
Source
File: bp-groups/classes/class-bp-groups-component.php
public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
$bp = buddypress();
// Determine user to use.
if ( bp_displayed_user_domain() ) {
$user_domain = bp_displayed_user_domain();
} elseif ( bp_loggedin_user_domain() ) {
$user_domain = bp_loggedin_user_domain();
} else {
$user_domain = false;
}
// Only grab count if we're on a user page.
if ( bp_is_user() ) {
$class = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count';
$nav_name = sprintf(
/* translators: %s: Group count for the current user */
__( 'Groups %s', 'buddyboss' ),
sprintf(
'<span class="%s">%s</span>',
esc_attr( $class ),
bp_get_total_group_count_for_user()
)
);
} else {
$nav_name = __( 'Groups', 'buddyboss' );
}
$slug = bp_get_groups_slug();
// Add 'Groups' to the main navigation.
$main_nav = array(
'name' => $nav_name,
'slug' => $slug,
'position' => 70,
'screen_function' => 'groups_screen_my_groups',
'default_subnav_slug' => 'my-groups',
'item_css_id' => $this->id
);
if ( ! empty( $user_domain ) ) {
$access = bp_core_can_edit_settings();
$groups_link = trailingslashit( $user_domain . $slug );
// Add the My Groups nav item.
$sub_nav[] = array(
'name' => __( 'My Groups', 'buddyboss' ),
'slug' => 'my-groups',
'parent_url' => $groups_link,
'parent_slug' => $slug,
'screen_function' => 'groups_screen_my_groups',
'position' => 10,
'item_css_id' => 'groups-my-groups'
);
// Add the Group Invites nav item.
$sub_nav[] = array(
'name' => __( 'Invitations', 'buddyboss' ),
'slug' => 'invites',
'parent_url' => $groups_link,
'parent_slug' => $slug,
'screen_function' => 'groups_screen_group_invites',
'user_has_access' => $access,
'position' => 30
);
parent::setup_nav( $main_nav, $sub_nav );
}
if ( bp_is_groups_component() && bp_is_single_item() ) {
// Reset sub nav.
$sub_nav = array();
/*
* The top-level Groups item is called 'Memberships' for legacy reasons.
* It does not appear in the interface.
*/
bp_core_new_nav_item( array(
'name' => __( 'My Groups', 'buddyboss' ),
'slug' => $this->current_group->slug,
'position' => -1, // Do not show in BuddyBar.
'screen_function' => 'groups_screen_group_home',
'default_subnav_slug' => $this->default_extension,
'item_css_id' => $this->id
), 'groups' );
$group_link = bp_get_group_permalink( $this->current_group );
// Add the "Members" subnav item, as this will always be present.
$sub_nav[] = array(
'name' => sprintf( apply_filters('group_single_members_label', __( 'Members', 'buddyboss' ) ). __( ' %s', 'buddyboss' ), '<span>' . number_format( $this->current_group->total_member_count ) . '</span>' ),
'slug' => 'members',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_members',
'user_has_access' => $this->current_group->user_has_access,
'position' => 10,
'item_css_id' => 'members',
);
$members_link = trailingslashit( $group_link . 'members' );
// Common params to all member sub nav items.
$default_params = array(
'parent_url' => $members_link,
'parent_slug' => $this->current_group->slug . '_members',
'screen_function' => 'groups_screen_group_members',
'user_has_access' => $this->current_group->user_has_access,
'show_in_admin_bar' => true,
);
// $sub_nav[] = array_merge( array(
// 'name' => __( 'All Members', 'buddyboss' ),
// 'slug' => 'all-members',
// 'position' => 0,
// ), $default_params );
//
// $sub_nav[] = array_merge( array(
// 'name' => __( 'Group Leaders', 'buddyboss' ),
// 'slug' => 'leaders',
// 'position' => 10,
// ), $default_params );
if ( bp_is_active( 'activity' ) ) {
$sub_nav[] = array(
'name' => __( 'Feed', 'buddyboss' ),
'slug' => 'activity',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_activity',
'position' => 11,
'user_has_access' => $this->current_group->user_has_access,
'item_css_id' => 'activity',
'no_access_url' => $group_link,
);
}
if ( bp_enable_group_hierarchies() ) {
$descendant_groups = bp_get_descendent_groups( bp_get_current_group_id(), bp_loggedin_user_id() );
if ( $total_descendant = count( $descendant_groups ) ) {
$sub_nav[] = array(
'name' => sprintf( __( 'Subgroups', 'buddyboss' ), '<span>' . number_format( $total_descendant ) . '</span>' ),
'slug' => 'subgroups',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_subgroups',
'position' => 20,
'user_has_access' => $this->current_group->user_has_access,
'item_css_id' => 'subgroups',
'no_access_url' => $group_link,
);
}
}
// If this is a private group, and the user is not a
// member and does not have an outstanding invitation,
// show a "Request Membership" nav item.
if ( groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) || bp_current_user_can( 'groups_request_membership', array( 'group_id' => $this->current_group->id ) ) ) {
$sub_nav[] = array(
'name' => __( 'Request Access', 'buddyboss' ),
'slug' => 'request-membership',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_request_membership',
'position' => 30
);
}
if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) {
$sub_nav[] = array(
'name' => __( 'Send Invites', 'buddyboss' ),
'slug' => 'send-invites',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_invite',
'item_css_id' => 'invite',
'position' => 70,
'user_has_access' => $this->current_group->user_has_access,
'no_access_url' => $group_link,
);
}
if ( bp_is_active( 'media' ) && bp_is_group_media_support_enabled() ) {
$sub_nav[] = array(
'name' => __( 'Photos', 'buddyboss' ),
'slug' => 'photos',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_media',
'position' => 80,
'user_has_access' => $this->current_group->user_has_access,
'item_css_id' => 'photos',
'no_access_url' => $group_link,
);
if ( bp_is_group_albums_support_enabled() ) {
$sub_nav[] = array(
'name' => __( 'Albums', 'buddyboss' ),
'slug' => 'albums',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_albums',
'position' => 85,
'user_has_access' => $this->current_group->user_has_access,
'item_css_id' => 'albums',
'no_access_url' => $group_link,
);
}
}
// If the user is a group admin, then show the group admin nav item.
if ( bp_is_item_admin() ) {
$sub_nav[] = array(
'name' => __( 'Manage', 'buddyboss' ),
'slug' => 'admin',
'parent_url' => $group_link,
'parent_slug' => $this->current_group->slug,
'screen_function' => 'groups_screen_group_admin',
'position' => 1000,
'user_has_access' => true,
'item_css_id' => 'admin',
'no_access_url' => $group_link,
);
$admin_link = trailingslashit( $group_link . 'admin' );
// Common params to all nav items.
$default_params = array(
'parent_url' => $admin_link,
'parent_slug' => $this->current_group->slug . '_manage',
'screen_function' => 'groups_screen_group_admin',
'user_has_access' => bp_is_item_admin(),
'show_in_admin_bar' => true,
);
$sub_nav[] = array_merge( array(
'name' => __( 'Details', 'buddyboss' ),
'slug' => 'edit-details',
'position' => 0,
), $default_params );
$sub_nav[] = array_merge( array(
'name' => __( 'Settings', 'buddyboss' ),
'slug' => 'group-settings',
'position' => 10,
), $default_params );
if ( ! bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars ) {
$sub_nav[] = array_merge( array(
'name' => __( 'Photo', 'buddyboss' ),
'slug' => 'group-avatar',
'position' => 20,
), $default_params );
}
if ( bp_group_use_cover_image_header() ) {
$sub_nav[] = array_merge( array(
'name' => __( 'Cover Photo', 'buddyboss' ),
'slug' => 'group-cover-image',
'position' => 25,
), $default_params );
}
$sub_nav[] = array_merge( array(
'name' => __( 'Members', 'buddyboss' ),
'slug' => 'manage-members',
'position' => 30,
), $default_params );
if ( 'private' == $this->current_group->status ) {
$sub_nav[] = array_merge( array(
'name' => __( 'Requests', 'buddyboss' ),
'slug' => 'membership-requests',
'position' => 40,
), $default_params );
}
$sub_nav[] = array_merge( array(
'name' => __( 'Delete', 'buddyboss' ),
'slug' => 'delete-group',
'position' => 1000,
), $default_params );
}
foreach ( $sub_nav as $nav ) {
bp_core_new_subnav_item( $nav, 'groups' );
}
}
if ( isset( $this->current_group->user_has_access ) ) {
/**
* Fires at the end of the groups navigation setup if user has access.
*
* @since BuddyPress 1.0.2
*
* @param bool $user_has_access Whether or not user has access.
*/
do_action( 'groups_setup_nav', $this->current_group->user_has_access );
} else {
/** This action is documented in bp-groups/bp-groups-loader.php */
do_action( 'groups_setup_nav');
}
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.