bp_groups_group_admin_menu()

Add the Group Admin top-level menu when viewing group pages.

Description

Return

(false|null) False if not on a group page, or if user does not have access to group admin options.

Source

File: bp-groups/bp-groups-adminbar.php

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function bp_groups_group_admin_menu() {
    global $wp_admin_bar;
    $bp = buddypress();
 
    // Only show if viewing a group.
    if ( ! bp_is_group() || bp_is_group_create() ) {
        return false;
    }
 
    // Only show this menu to group admins and super admins.
    if ( ! bp_current_user_can( 'bp_moderate' ) && ! bp_group_is_admin() ) {
        return false;
    }
 
    // Unique ID for the 'Edit Group' menu.
    $bp->group_admin_menu_id = 'group-admin';
 
    // Add the top-level Group Admin button.
    $wp_admin_bar->add_menu( array(
        'id'    => $bp->group_admin_menu_id,
        'title' => __( 'Edit Group', 'buddyboss' ),
        'href'  => bp_get_group_permalink( $bp->groups->current_group ) . 'admin/edit-details/'
    ) );
 
    // Index of the Manage tabs parent slug.
    $secondary_nav_items = $bp->groups->nav->get_secondary( array( 'parent_slug' => $bp->groups->current_group->slug . '_manage' ) );
 
    // Check if current group has Manage tabs.
    if ( ! $secondary_nav_items ) {
        return;
    }
 
    // Build the Group Admin menus.
    foreach ( $secondary_nav_items as $menu ) {
        /**
         * Should we add the current manage link in the Group's "Edit" Admin Bar menu ?
         *
         * All core items will be added, plugins can use a new parameter in the BP Group Extension API
         * to also add the link to the "edit screen" of their group component. To do so, set the
         * the 'show_in_admin_bar' argument of your edit screen to true
         */
        if ( $menu->show_in_admin_bar ) {
            $title = sprintf( __( 'Edit Group %s', 'buddyboss' ), $menu->name );
 
            // Title is specific for delete.
            if ( 'delete-group' == $menu->slug ) {
                $title = sprintf( __( '%s Group', 'buddyboss' ), $menu->name );
 
                if ( bp_is_active( 'forums' ) && function_exists( 'bbp_is_group_forums_active' ) ) {
                    if ( bbp_is_group_forums_active() ) {
                        $wp_admin_bar->add_menu( array(
                            'parent' => $bp->group_admin_menu_id,
                            'id'     => get_option( '_bbp_forum_slug', 'forum' ),
                            'title'  => 'Edit Group Discussion',
                            'href'   => bp_get_groups_action_link( 'admin/' . get_option( '_bbp_forum_slug', 'forum' ) )
                        ) );
                    }
                }
            }
 
            $wp_admin_bar->add_menu( array(
                'parent' => $bp->group_admin_menu_id,
                'id'     => $menu->slug,
                'title'  => $title,
                'href'   => bp_get_groups_action_link( 'admin/' . $menu->slug )
            ) );
        }
    }
}

Changelog

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.