Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/10/2014 07:13:04 PM (11 years ago)
Author:
imath
Message:

Improve Group's Edit WP Admin Bar menu

Use the group's manage options nav to populate the different edit links of the group's Edit WP Admin Bar.
Introduce a new parameter show_in_admin_bar for the edit screen property of the Group Extension API to allow plugins add their edit link into this Admin Bar (if this parameter is set to true).

props boonebgorges

Fixes #6002

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-adminbar.php

    r9026 r9131  
    2424 */
    2525function bp_groups_group_admin_menu() {
    26     global $wp_admin_bar, $bp;
     26    global $wp_admin_bar;
     27    $bp = buddypress();
    2728
    2829    // Only show if viewing a group
    29     if ( !bp_is_group() )
     30    if ( ! bp_is_group() || bp_is_group_create() ) {
    3031        return false;
     32    }
    3133
    3234    // Only show this menu to group admins and super admins
    33     if ( !bp_current_user_can( 'bp_moderate' ) && !bp_group_is_admin() )
     35    if ( ! bp_current_user_can( 'bp_moderate' ) && ! bp_group_is_admin() ) {
    3436        return false;
     37    }
    3538
    3639    // Unique ID for the 'Edit Group' menu
     
    4447    ) );
    4548
    46     // Group Admin > Edit details
    47     $wp_admin_bar->add_menu( array(
    48         'parent' => $bp->group_admin_menu_id,
    49         'id'     => 'edit-details',
    50         'title'  => __( 'Edit Details', 'buddypress' ),
    51         'href'   =>  bp_get_groups_action_link( 'admin/edit-details' )
    52     ) );
     49    // Index of the Manage tabs parent slug
     50    $nav_index = $bp->groups->current_group->slug . '_manage';
    5351
    54     // Group Admin > Group settings
    55     $wp_admin_bar->add_menu( array(
    56         'parent' => $bp->group_admin_menu_id,
    57         'id'     => 'group-settings',
    58         'title'  => __( 'Edit Settings', 'buddypress' ),
    59         'href'   =>  bp_get_groups_action_link( 'admin/group-settings' )
    60     ) );
    61 
    62     // Group Admin > Group avatar
    63     if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) && $bp->avatar->show_avatars ) {
    64         $wp_admin_bar->add_menu( array(
    65             'parent' => $bp->group_admin_menu_id,
    66             'id'     => 'group-avatar',
    67             'title'  => __( 'Edit Profile Photo', 'buddypress' ),
    68             'href'   =>  bp_get_groups_action_link( 'admin/group-avatar' )
    69         ) );
     52    // Check if current group has Manage tabs
     53    if ( empty( $bp->bp_options_nav[ $nav_index ] ) ) {
     54        return;
    7055    }
    7156
    72     // Group Admin > Manage invitations
    73     if ( bp_is_active( 'friends' ) ) {
    74         $wp_admin_bar->add_menu( array(
    75             'parent' => $bp->group_admin_menu_id,
    76             'id'     => 'manage-invitations',
    77             'title'  => __( 'Manage Invitations', 'buddypress' ),
    78             'href'   =>  bp_get_groups_action_link( 'send-invites' )
    79         ) );
     57    // Build the Group Admin menus
     58    foreach ( $bp->bp_options_nav[ $nav_index ] as $menu ) {
     59        /**
     60         * Should we add the current manage link in the Group's "Edit" Admin Bar menu ?
     61         *
     62         * All core items will be added, plugins can use a new parameter in the BP Group Extension API
     63         * to also add the link to the "edit screen" of their group component. To do so, set the
     64         * the 'show_in_admin_bar' argument of your edit screen to true
     65         */
     66        if ( $menu['show_in_admin_bar'] ) {
     67            $title = sprintf( _x( 'Edit Group %s', 'Group WP Admin Bar manage links', 'buddypress' ), $menu['name'] );
     68
     69            // Title is specific for delete
     70            if ( 'delete-group' == $menu['slug'] ) {
     71                $title = sprintf( _x( '%s Group', 'Group WP Admin Bar delete link', 'buddypress' ), $menu['name'] );
     72            }
     73
     74            $wp_admin_bar->add_menu( array(
     75                'parent' => $bp->group_admin_menu_id,
     76                'id'     => $menu['slug'],
     77                'title'  => $title,
     78                'href'   => bp_get_groups_action_link( 'admin/' . $menu['slug'] )
     79            ) );
     80        }
    8081    }
    81 
    82     // Group Admin > Manage members
    83     $wp_admin_bar->add_menu( array(
    84         'parent' => $bp->group_admin_menu_id,
    85         'id'     => 'manage-members',
    86         'title'  => __( 'Manage Members', 'buddypress' ),
    87         'href'   =>  bp_get_groups_action_link( 'admin/manage-members' )
    88     ) );
    89 
    90     // Group Admin > Membership Requests
    91     if ( bp_get_group_status( $bp->groups->current_group ) == 'private' ) {
    92         $wp_admin_bar->add_menu( array(
    93             'parent' => $bp->group_admin_menu_id,
    94             'id'     => 'membership-requests',
    95             'title'  => __( 'Membership Requests', 'buddypress' ),
    96             'href'   =>  bp_get_groups_action_link( 'admin/membership-requests' )
    97         ) );
    98     }
    99 
    100     // Delete Group
    101     $wp_admin_bar->add_menu( array(
    102         'parent' => $bp->group_admin_menu_id,
    103         'id'     => 'delete-group',
    104         'title'  => __( 'Delete Group', 'buddypress' ),
    105         'href'   =>  bp_get_groups_action_link( 'admin/delete-group' )
    106     ) );
    10782}
    10883add_action( 'admin_bar_menu', 'bp_groups_group_admin_menu', 99 );
Note: See TracChangeset for help on using the changeset viewer.