[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Members Toolbar.
   4   *
   5   * Handles the member functions related to the WordPress Toolbar.
   6   *
   7   * @package BuddyPress
   8   * @subpackage MembersAdminBar
   9   * @since 1.5.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * Add the "My Account" menu and all submenus.
  17   *
  18   * @since 1.6.0
  19   *
  20   * @todo Deprecate WP 3.2 Toolbar compatibility when we drop 3.2 support.
  21   */
  22  function bp_members_admin_bar_my_account_menu() {
  23      global $wp_admin_bar;
  24  
  25      // Bail if this is an ajax request.
  26      if ( wp_doing_ajax() ) {
  27          return;
  28      }
  29  
  30      // Logged in user.
  31      if ( is_user_logged_in() ) {
  32  
  33          $bp = buddypress();
  34  
  35          // Stored in the global so we can add menus easily later on.
  36          $bp->my_account_menu_id = 'my-account-buddypress';
  37  
  38          // Create the main 'My Account' menu.
  39          $wp_admin_bar->add_node( array(
  40              'id'     => $bp->my_account_menu_id,
  41              'group'  => true,
  42              'title'  => __( 'Edit My Profile', 'buddypress' ),
  43              'href'   => bp_loggedin_user_domain(),
  44              'meta'   => array(
  45              'class'  => 'ab-sub-secondary'
  46          ) ) );
  47  
  48          // Show login and sign-up links.
  49      } elseif ( !empty( $wp_admin_bar ) ) {
  50  
  51          add_filter( 'show_admin_bar', '__return_true' );
  52  
  53          // Create the main 'My Account' menu.
  54          $wp_admin_bar->add_node( array(
  55              'id'    => 'bp-login',
  56              'title' => __( 'Log In', 'buddypress' ),
  57              'href'  => wp_login_url( bp_get_requested_url() )
  58          ) );
  59  
  60          // Sign up.
  61          if ( bp_get_signup_allowed() ) {
  62              $wp_admin_bar->add_node( array(
  63                  'id'    => 'bp-register',
  64                  'title' => __( 'Register', 'buddypress' ),
  65                  'href'  => bp_get_signup_page()
  66              ) );
  67          }
  68      }
  69  }
  70  add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_my_account_menu', 4 );
  71  
  72  /**
  73   * Add the User Admin top-level menu to user pages.
  74   *
  75   * @since 1.5.0
  76   */
  77  function bp_members_admin_bar_user_admin_menu() {
  78      global $wp_admin_bar;
  79  
  80      // Only show if viewing a user.
  81      if ( !bp_is_user() )
  82          return false;
  83  
  84      // Don't show this menu to non site admins or if you're viewing your own profile.
  85      if ( !current_user_can( 'edit_users' ) || bp_is_my_profile() )
  86          return false;
  87  
  88      $bp = buddypress();
  89  
  90      // Unique ID for the 'My Account' menu.
  91      $bp->user_admin_menu_id = 'user-admin';
  92  
  93      // Add the top-level User Admin button.
  94      $wp_admin_bar->add_node( array(
  95          'id'    => $bp->user_admin_menu_id,
  96          'title' => __( 'Edit Member', 'buddypress' ),
  97          'href'  => bp_displayed_user_domain()
  98      ) );
  99  
 100      if ( bp_is_active( 'xprofile' ) ) {
 101          // User Admin > Edit this user's profile.
 102          $wp_admin_bar->add_node( array(
 103              'parent' => $bp->user_admin_menu_id,
 104              'id'     => $bp->user_admin_menu_id . '-edit-profile',
 105              'title'  => __( "Edit Profile", 'buddypress' ),
 106              'href'   => bp_get_members_component_link( $bp->profile->id, 'edit' )
 107          ) );
 108  
 109          // User Admin > Edit this user's avatar.
 110          if ( buddypress()->avatar->show_avatars ) {
 111              $wp_admin_bar->add_node( array(
 112                  'parent' => $bp->user_admin_menu_id,
 113                  'id'     => $bp->user_admin_menu_id . '-change-avatar',
 114                  'title'  => __( "Edit Profile Photo", 'buddypress' ),
 115                  'href'   => bp_get_members_component_link( $bp->profile->id, 'change-avatar' )
 116              ) );
 117          }
 118  
 119          // User Admin > Edit this user's cover image.
 120          if ( bp_displayed_user_use_cover_image_header() ) {
 121              $wp_admin_bar->add_node( array(
 122                  'parent' => $bp->user_admin_menu_id,
 123                  'id'     => $bp->user_admin_menu_id . '-change-cover-image',
 124                  'title'  => __( 'Edit Cover Image', 'buddypress' ),
 125                  'href'   => bp_get_members_component_link( $bp->profile->id, 'change-cover-image' )
 126              ) );
 127          }
 128  
 129      }
 130  
 131      if ( bp_is_active( 'settings' ) ) {
 132          // User Admin > Spam/unspam.
 133          $wp_admin_bar->add_node( array(
 134              'parent' => $bp->user_admin_menu_id,
 135              'id'     => $bp->user_admin_menu_id . '-user-capabilities',
 136              'title'  => __( 'User Capabilities', 'buddypress' ),
 137              'href'   => bp_displayed_user_domain() . 'settings/capabilities/'
 138          ) );
 139  
 140          // User Admin > Delete Account.
 141          $wp_admin_bar->add_node( array(
 142              'parent' => $bp->user_admin_menu_id,
 143              'id'     => $bp->user_admin_menu_id . '-delete-user',
 144              'title'  => __( 'Delete Account', 'buddypress' ),
 145              'href'   => bp_displayed_user_domain() . 'settings/delete-account/'
 146          ) );
 147  
 148      }
 149  
 150  }
 151  add_action( 'admin_bar_menu', 'bp_members_admin_bar_user_admin_menu', 99 );
 152  
 153  /**
 154   * Build the "Notifications" dropdown.
 155   *
 156   * @since 1.5.0
 157   *
 158   * @return bool
 159   */
 160  function bp_members_admin_bar_notifications_menu() {
 161  
 162      // Bail if notifications is not active.
 163      if ( ! bp_is_active( 'notifications' ) ) {
 164          return false;
 165      }
 166  
 167      bp_notifications_toolbar_menu();
 168  }
 169  add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
 170  
 171  /**
 172   * Remove rogue WP core Edit menu when viewing a single user.
 173   *
 174   * @since 1.6.0
 175   */
 176  function bp_members_remove_edit_page_menu() {
 177      if ( bp_is_user() ) {
 178          remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
 179      }
 180  }
 181  add_action( 'add_admin_bar_menus', 'bp_members_remove_edit_page_menu' );
 182  
 183  /**
 184   * Add the "Invitations" menu and submenus.
 185   *
 186   * @since 8.0.0
 187   */
 188  function bp_members_admin_bar_add_invitations_menu() {
 189      global $wp_admin_bar;
 190  
 191      // Bail if this is an ajax request.
 192      if ( wp_doing_ajax() ) {
 193          return;
 194      }
 195  
 196      if ( bp_current_user_can( 'bp_members_invitations_view_screens' ) ) {
 197          $bp               = buddypress();
 198          $invitations_link = trailingslashit( bp_loggedin_user_domain() . bp_get_members_invitations_slug() );
 199  
 200          $wp_admin_bar->add_node(
 201              array(
 202                  'id'     => $bp->my_account_menu_id . '-invitations',
 203                  'parent' => $bp->my_account_menu_id,
 204                  'title'  => __( 'Invitations', 'buddypress' ),
 205                  'href'   => $invitations_link,
 206                  'meta'   => array(
 207                      'class'  => 'ab-sub-secondary'
 208                  )
 209              )
 210          );
 211  
 212          if ( bp_current_user_can( 'bp_members_invitations_view_send_screen' ) ) {
 213              $wp_admin_bar->add_node(
 214                  array(
 215                      'id'     => $bp->my_account_menu_id . '-invitations-send',
 216                      'parent' => $bp->my_account_menu_id . '-invitations',
 217                      'title'  => __( 'Send Invites', 'buddypress' ),
 218                      'href'   => $invitations_link . 'send-invites/',
 219                      'meta'   => array(
 220                          'class'  => 'ab-sub-secondary'
 221                      )
 222                  )
 223              );
 224          }
 225  
 226          $wp_admin_bar->add_node(
 227              array(
 228                  'id'     => $bp->my_account_menu_id . '-invitations-list',
 229                  'parent' => $bp->my_account_menu_id . '-invitations',
 230                  'title'  => __( 'Pending Invites', 'buddypress' ),
 231                  'href'   => $invitations_link . 'list-invites/',
 232                  'meta'   => array(
 233                      'class'  => 'ab-sub-secondary'
 234                  )
 235              )
 236          );
 237      }
 238  }
 239  add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_add_invitations_menu', 90 );


Generated: Thu Jul 29 01:01:39 2021 Cross-referenced by PHPXref 0.7.1