[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/ -> bp-groups-adminbar.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Groups Toolbar.
   4   *
   5   * Handles the groups functions related to the WordPress Toolbar.
   6   *
   7   * @package BuddyPress
   8   * @subpackage Groups
   9   * @since 1.5.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * Add the Group Admin top-level menu when viewing group pages.
  17   *
  18   * @since 1.5.0
  19   *
  20   * @todo Add dynamic menu items for group extensions.
  21   *
  22   * @return false|null False if not on a group page, or if user does not have
  23   *                    access to group admin options.
  24   */
  25  function bp_groups_group_admin_menu() {
  26      global $wp_admin_bar;
  27      $bp = buddypress();
  28  
  29      // Only show if viewing a group.
  30      if ( ! bp_is_group() || bp_is_group_create() ) {
  31          return false;
  32      }
  33  
  34      // Only show this menu to group admins and super admins.
  35      if ( ! bp_current_user_can( 'bp_moderate' ) && ! bp_group_is_admin() ) {
  36          return false;
  37      }
  38  
  39      // Unique ID for the 'Edit Group' menu.
  40      $bp->group_admin_menu_id = 'group-admin';
  41  
  42      // Add the top-level Group Admin button.
  43      $wp_admin_bar->add_node( array(
  44          'id'    => $bp->group_admin_menu_id,
  45          'title' => __( 'Edit Group', 'buddypress' ),
  46          'href'  => bp_get_group_permalink( $bp->groups->current_group )
  47      ) );
  48  
  49      // Index of the Manage tabs parent slug.
  50      $secondary_nav_items = $bp->groups->nav->get_secondary( array( 'parent_slug' => $bp->groups->current_group->slug . '_manage' ) );
  51  
  52      // Check if current group has Manage tabs.
  53      if ( ! $secondary_nav_items ) {
  54          return;
  55      }
  56  
  57      // Build the Group Admin menus.
  58      foreach ( $secondary_nav_items 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              /* translators: %s the group menu name */
  68              $title = sprintf( _x( 'Edit Group %s', 'Group WP Admin Bar manage links', 'buddypress' ), $menu->name );
  69  
  70              // Title is specific for delete.
  71              if ( 'delete-group' == $menu->slug ) {
  72                  /* translators: %s the group menu name */
  73                  $title = sprintf( _x( '%s Group', 'Group WP Admin Bar delete link', 'buddypress' ), $menu->name );
  74              }
  75  
  76              $wp_admin_bar->add_node( array(
  77                  'parent' => $bp->group_admin_menu_id,
  78                  'id'     => $menu->slug,
  79                  'title'  => $title,
  80                  'href'   => bp_get_groups_action_link( 'admin/' . $menu->slug )
  81              ) );
  82          }
  83      }
  84  }
  85  add_action( 'admin_bar_menu', 'bp_groups_group_admin_menu', 99 );
  86  
  87  /**
  88   * Remove rogue WP core Edit menu when viewing a single group.
  89   *
  90   * @since 1.6.0
  91   */
  92  function bp_groups_remove_edit_page_menu() {
  93      if ( bp_is_group() ) {
  94          remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
  95      }
  96  }
  97  add_action( 'add_admin_bar_menus', 'bp_groups_remove_edit_page_menu' );


Generated: Wed Apr 24 01:01:03 2024 Cross-referenced by PHPXref 0.7.1