Advertisement
Ipstenu

BP Notifications

Jun 29th, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: BuddyPress Notifications
  4. Plugin URI:
  5. Description: Adding BuddyPress Notifications to the WordPress Admin Bar
  6. Version: 1.0
  7. Author: Mika A. Epstein
  8. Author URI: http://www.ipstenu.org/
  9. */
  10.  
  11. // The Stylin
  12.  
  13. function bp_admin_bar_add_notes_stylesheet() {
  14.     if ( is_user_logged_in() ) {
  15.     ?>
  16.         <style type="text/css">
  17.             #wpadminbar .quicklinks a span#bp-awaiting-some {
  18.                 background: #F8E0E0;
  19.                 color: #C80000;
  20.                 text-shadow: none;
  21.                 display: inline;
  22.                 padding: 2px 5px;
  23.                 font-size: 10px;
  24.                 font-weight: bold;
  25.                 -moz-border-radius: 10px;
  26.                 -khtml-border-radius: 10px;
  27.                 -webkit-border-radius: 10px;
  28.                 border-radius: 10px;
  29.             }
  30.  
  31.             #wpadminbar .quicklinks a span#bp-awaiting-none {
  32.                 background: #999;
  33.                 color: #333;
  34.                 text-shadow: none;
  35.                 display: inline;
  36.                 padding: 2px 5px;
  37.                 font-size: 10px;
  38.                 font-weight: bold;
  39.                 -moz-border-radius: 10px;
  40.                 -khtml-border-radius: 10px;
  41.                 -webkit-border-radius: 10px;
  42.                 border-radius: 10px;
  43.             }
  44.         </style>
  45.     <?php
  46.     }
  47. }
  48. add_action('wp_head', 'bp_admin_bar_add_notes_stylesheet');
  49. add_action('admin_head', 'bp_admin_bar_add_notes_stylesheet');
  50.  
  51. // The Code
  52. function bp_admin_bar_add_notes() {
  53.         global $wp_admin_bar, $user_identity, $bp;
  54.         $user_id = get_current_user_id();
  55.  
  56.         /* Add my stuff */
  57.         if ( 0 != $user_id ) {
  58.  
  59.                 // Notifications
  60.                 $idbp = ( ! empty( $avatar ) ) ? 'bp-bp-menu': 'bp-bp';
  61.  
  62.                 if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) {
  63.                     $ncount = count( $notifications );
  64.                     $ncount = "<span id='bp-awaiting-some' class='pending-count'>" . number_format_i18n( $ncount ) . "</span>";
  65.                 }
  66.                 else {
  67.                     $ncount = "<span id='bp-awaiting-none' class='pending-count'>0</span>";
  68.                 }
  69.                 $wp_admin_bar->add_menu( array( 'id' => $idbp, 'title' => sprintf( __('%s'), $ncount ) , 'href' => $bp->loggedin_user->domain ) );
  70.  
  71.                 if ( $notifications ) {
  72.                     $counter = 0;
  73.                     for ( $i = 0; $i < count($notifications); $i++ ) {
  74.                         $wp_admin_bar->add_menu( array( 'parent' => $idbp, 'title' => $notifications[$i], 'href' => $bp->loggedin_user->domain ) );
  75.                         $counter++;
  76.                   }
  77.                 }
  78.                 else {
  79.                     $wp_admin_bar->add_menu( array( 'parent' => $idbp, 'title' => __('No New Notifications'), 'href' => $bp->loggedin_user->domain ) );
  80.                 }
  81.         }
  82. }
  83.  
  84. add_action( 'admin_bar_menu', 'bp_admin_bar_add_notes', 10 );
  85.  
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement