[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Notifications Admin Bar functions.
   4   *
   5   * Admin Bar functions for the Notifications component.
   6   *
   7   * @package BuddyPress
   8   * @subpackage NotificationsToolbar
   9   * @since 1.9.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * Build the "Notifications" dropdown.
  17   *
  18   * @since 1.9.0
  19   *
  20   * @return bool
  21   */
  22  function bp_notifications_toolbar_menu() {
  23      global $wp_admin_bar;
  24  
  25      if ( ! is_user_logged_in() ) {
  26          return false;
  27      }
  28  
  29      $notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
  30      $count         = ! empty( $notifications ) ? count( $notifications ) : 0;
  31      $alert_class   = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
  32      $menu_title    = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . number_format_i18n( $count ) . '</span>';
  33      $menu_link     = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
  34  
  35      // Add the top-level Notifications button.
  36      $wp_admin_bar->add_node( array(
  37          'parent' => 'top-secondary',
  38          'id'     => 'bp-notifications',
  39          'title'  => $menu_title,
  40          'href'   => $menu_link,
  41      ) );
  42  
  43      if ( ! empty( $notifications ) ) {
  44          foreach ( (array) $notifications as $notification ) {
  45              $wp_admin_bar->add_node( array(
  46                  'parent' => 'bp-notifications',
  47                  'id'     => 'notification-' . $notification->id,
  48                  'title'  => $notification->content,
  49                  'href'   => $notification->href,
  50              ) );
  51          }
  52      } else {
  53          $wp_admin_bar->add_node( array(
  54              'parent' => 'bp-notifications',
  55              'id'     => 'no-notifications',
  56              'title'  => __( 'No new notifications', 'buddypress' ),
  57              'href'   => $menu_link,
  58          ) );
  59      }
  60  
  61      return true;
  62  }
  63  add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );


Generated: Thu Dec 26 01:01:04 2024 Cross-referenced by PHPXref 0.7.1