[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Core Toolbar.
   4   *
   5   * Handles the core functions related to the WordPress Toolbar.
   6   *
   7   * @package BuddyPress
   8   * @subpackage Core
   9   * @since 1.0.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * Add the secondary BuddyPress area to the my-account menu.
  17   *
  18   * @since 1.6.0
  19   *
  20   * @global WP_Admin_Bar $wp_admin_bar.
  21   */
  22  function bp_admin_bar_my_account_root() {
  23      global $wp_admin_bar;
  24  
  25      // Bail if this is an ajax request.
  26      if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) )
  27          return;
  28  
  29      // Only add menu for logged in user.
  30      if ( is_user_logged_in() ) {
  31  
  32          // Add secondary parent item for all BuddyPress components.
  33          $wp_admin_bar->add_menu( array(
  34              'parent'    => 'my-account',
  35              'id'        => 'my-account-buddypress',
  36              'title'     => __( 'My Account', 'buddypress' ),
  37              'group'     => true,
  38              'meta'      => array(
  39                  'class' => 'ab-sub-secondary'
  40              )
  41          ) );
  42      }
  43  }
  44  add_action( 'admin_bar_menu', 'bp_admin_bar_my_account_root', 100 );
  45  
  46  /**
  47   * Handle the Toolbar/BuddyBar business.
  48   *
  49   * @since 1.2.0
  50   */
  51  function bp_core_load_admin_bar() {
  52  
  53      // Show the Toolbar for logged out users.
  54      if ( ! is_user_logged_in() && (int) bp_get_option( 'hide-loggedout-adminbar' ) != 1 ) {
  55          show_admin_bar( true );
  56      }
  57  
  58      // Hide the WordPress Toolbar and show the BuddyBar.
  59      if ( ! bp_use_wp_admin_bar() ) {
  60          _doing_it_wrong( __FUNCTION__, __( 'The BuddyBar is no longer supported. Please migrate to the WordPress toolbar as soon as possible.', 'buddypress' ), '2.1.0' );
  61  
  62          // Load deprecated code if not available.
  63          if ( ! function_exists( 'bp_core_admin_bar' ) ) {
  64              require buddypress()->plugin_dir . 'bp-core/deprecated/2.1.php';
  65          }
  66  
  67          // Keep the WP Toolbar from loading.
  68          show_admin_bar( false );
  69  
  70          // Actions used to build the BP Toolbar.
  71          add_action( 'bp_adminbar_logo',  'bp_adminbar_logo'               );
  72          add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu',    2   );
  73          add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu',  4   );
  74          add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6   );
  75          add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu',   100 );
  76  
  77          // Actions used to append BP Toolbar to footer.
  78          add_action( 'wp_footer',    'bp_core_admin_bar', 8 );
  79          add_action( 'admin_footer', 'bp_core_admin_bar'    );
  80      }
  81  }
  82  add_action( 'init', 'bp_core_load_admin_bar', 9 );
  83  
  84  /**
  85   * Handle the enqueueing of toolbar CSS.
  86   *
  87   * This function exists mostly for backwards compatibility reasons, so anyone
  88   * previously unhooking this function can continue to do so. It's hooked to
  89   * the `bp_init` action in `bp-core-actions.php`.
  90   *
  91   * @since 1.5.0
  92   */
  93  function bp_core_load_admin_bar_css() {
  94      add_action( 'bp_enqueue_scripts',       'bp_core_enqueue_admin_bar_css', 1 );
  95      add_action( 'bp_admin_enqueue_scripts', 'bp_core_enqueue_admin_bar_css', 1 );
  96  }
  97  
  98  /**
  99   * Enqueue supplemental WordPress Toolbar styling.
 100   *
 101   * @since 2.1.0
 102   *
 103   * @see bp_core_register_common_styles()
 104   * @see bp_core_load_admin_bar_css()
 105   */
 106  function bp_core_enqueue_admin_bar_css() {
 107  
 108      // Bail if not using WordPress's admin bar or it's not showing on this
 109      // page request.
 110      if ( ! bp_use_wp_admin_bar() || ! is_admin_bar_showing() ) {
 111          return;
 112      }
 113  
 114      // Enqueue the additional adminbar css.
 115      wp_enqueue_style( 'bp-admin-bar' );
 116  }


Generated: Tue Jul 23 01:01:40 2019 Cross-referenced by PHPXref 0.7.1