[ 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 ( defined( 'DOING_AJAX' ) )
  27          return;
  28  
  29      // Logged in user.
  30      if ( is_user_logged_in() ) {
  31  
  32          $bp = buddypress();
  33  
  34          // Stored in the global so we can add menus easily later on.
  35          $bp->my_account_menu_id = 'my-account-buddypress';
  36  
  37          // Create the main 'My Account' menu.
  38          $wp_admin_bar->add_node( array(
  39              'id'     => $bp->my_account_menu_id,
  40              'group'  => true,
  41              'title'  => __( 'Edit My Profile', 'buddypress' ),
  42              'href'   => bp_loggedin_user_domain(),
  43              'meta'   => array(
  44              'class'  => 'ab-sub-secondary'
  45          ) ) );
  46  
  47          // Show login and sign-up links.
  48      } elseif ( !empty( $wp_admin_bar ) ) {
  49  
  50          add_filter( 'show_admin_bar', '__return_true' );
  51  
  52          // Create the main 'My Account' menu.
  53          $wp_admin_bar->add_node( array(
  54              'id'    => 'bp-login',
  55              'title' => __( 'Log In', 'buddypress' ),
  56              'href'  => wp_login_url( bp_get_requested_url() )
  57          ) );
  58  
  59          // Sign up.
  60          if ( bp_get_signup_allowed() ) {
  61              $wp_admin_bar->add_node( array(
  62                  'id'    => 'bp-register',
  63                  'title' => __( 'Register', 'buddypress' ),
  64                  'href'  => bp_get_signup_page()
  65              ) );
  66          }
  67      }
  68  }
  69  add_action( 'bp_setup_admin_bar', 'bp_members_admin_bar_my_account_menu', 4 );
  70  
  71  /**
  72   * Add the User Admin top-level menu to user pages.
  73   *
  74   * @since 1.5.0
  75   */
  76  function bp_members_admin_bar_user_admin_menu() {
  77      global $wp_admin_bar;
  78  
  79      // Only show if viewing a user.
  80      if ( !bp_is_user() )
  81          return false;
  82  
  83      // Don't show this menu to non site admins or if you're viewing your own profile.
  84      if ( !current_user_can( 'edit_users' ) || bp_is_my_profile() )
  85          return false;
  86  
  87      $bp = buddypress();
  88  
  89      // Unique ID for the 'My Account' menu.
  90      $bp->user_admin_menu_id = 'user-admin';
  91  
  92      // Add the top-level User Admin button.
  93      $wp_admin_bar->add_node( array(
  94          'id'    => $bp->user_admin_menu_id,
  95          'title' => __( 'Edit Member', 'buddypress' ),
  96          'href'  => bp_displayed_user_domain()
  97      ) );
  98  
  99      if ( bp_is_active( 'xprofile' ) ) {
 100          // User Admin > Edit this user's profile.
 101          $wp_admin_bar->add_node( array(
 102              'parent' => $bp->user_admin_menu_id,
 103              'id'     => $bp->user_admin_menu_id . '-edit-profile',
 104              'title'  => __( "Edit Profile", 'buddypress' ),
 105              'href'   => bp_get_members_component_link( 'profile', 'edit' )
 106          ) );
 107  
 108          // User Admin > Edit this user's avatar.
 109          if ( buddypress()->avatar->show_avatars ) {
 110              $wp_admin_bar->add_node( array(
 111                  'parent' => $bp->user_admin_menu_id,
 112                  'id'     => $bp->user_admin_menu_id . '-change-avatar',
 113                  'title'  => __( "Edit Profile Photo", 'buddypress' ),
 114                  'href'   => bp_get_members_component_link( 'profile', 'change-avatar' )
 115              ) );
 116          }
 117  
 118          // User Admin > Edit this user's cover image.
 119          if ( bp_displayed_user_use_cover_image_header() ) {
 120              $wp_admin_bar->add_node( array(
 121                  'parent' => $bp->user_admin_menu_id,
 122                  'id'     => $bp->user_admin_menu_id . '-change-cover-image',
 123                  'title'  => __( 'Edit Cover Image', 'buddypress' ),
 124                  'href'   => bp_get_members_component_link( 'profile', 'change-cover-image' )
 125              ) );
 126          }
 127  
 128      }
 129  
 130      if ( bp_is_active( 'settings' ) ) {
 131          // User Admin > Spam/unspam.
 132          $wp_admin_bar->add_node( array(
 133              'parent' => $bp->user_admin_menu_id,
 134              'id'     => $bp->user_admin_menu_id . '-user-capabilities',
 135              'title'  => __( 'User Capabilities', 'buddypress' ),
 136              'href'   => bp_displayed_user_domain() . 'settings/capabilities/'
 137          ) );
 138  
 139          // User Admin > Delete Account.
 140          $wp_admin_bar->add_node( array(
 141              'parent' => $bp->user_admin_menu_id,
 142              'id'     => $bp->user_admin_menu_id . '-delete-user',
 143              'title'  => __( 'Delete Account', 'buddypress' ),
 144              'href'   => bp_displayed_user_domain() . 'settings/delete-account/'
 145          ) );
 146  
 147      }
 148  
 149  }
 150  add_action( 'admin_bar_menu', 'bp_members_admin_bar_user_admin_menu', 99 );
 151  
 152  /**
 153   * Build the "Notifications" dropdown.
 154   *
 155   * @since 1.5.0
 156   *
 157   * @return bool
 158   */
 159  function bp_members_admin_bar_notifications_menu() {
 160  
 161      // Bail if notifications is not active.
 162      if ( ! bp_is_active( 'notifications' ) ) {
 163          return false;
 164      }
 165  
 166      bp_notifications_toolbar_menu();
 167  }
 168  add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
 169  
 170  /**
 171   * Remove rogue WP core Edit menu when viewing a single user.
 172   *
 173   * @since 1.6.0
 174   */
 175  function bp_members_remove_edit_page_menu() {
 176      if ( bp_is_user() ) {
 177          remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
 178      }
 179  }
 180  add_action( 'add_admin_bar_menus', 'bp_members_remove_edit_page_menu' );


Generated: Fri Nov 15 01:01:37 2019 Cross-referenced by PHPXref 0.7.1