Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: BuddyPress Notifications
- Plugin URI:
- Description: Adding BuddyPress Notifications to the WordPress Admin Bar
- Version: 1.0
- Author: Mika A. Epstein
- Author URI: http://www.ipstenu.org/
- */
- // The Stylin
- function bp_admin_bar_add_notes_stylesheet() {
- if ( is_user_logged_in() ) {
- ?>
- <style type="text/css">
- #wpadminbar .quicklinks a span#bp-awaiting-some {
- background: #F8E0E0;
- color: #C80000;
- text-shadow: none;
- display: inline;
- padding: 2px 5px;
- font-size: 10px;
- font-weight: bold;
- -moz-border-radius: 10px;
- -khtml-border-radius: 10px;
- -webkit-border-radius: 10px;
- border-radius: 10px;
- }
- #wpadminbar .quicklinks a span#bp-awaiting-none {
- background: #999;
- color: #333;
- text-shadow: none;
- display: inline;
- padding: 2px 5px;
- font-size: 10px;
- font-weight: bold;
- -moz-border-radius: 10px;
- -khtml-border-radius: 10px;
- -webkit-border-radius: 10px;
- border-radius: 10px;
- }
- </style>
- <?php
- }
- }
- add_action('wp_head', 'bp_admin_bar_add_notes_stylesheet');
- add_action('admin_head', 'bp_admin_bar_add_notes_stylesheet');
- // The Code
- function bp_admin_bar_add_notes() {
- global $wp_admin_bar, $user_identity, $bp;
- $user_id = get_current_user_id();
- /* Add my stuff */
- if ( 0 != $user_id ) {
- // Notifications
- $idbp = ( ! empty( $avatar ) ) ? 'bp-bp-menu': 'bp-bp';
- if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) {
- $ncount = count( $notifications );
- $ncount = "<span id='bp-awaiting-some' class='pending-count'>" . number_format_i18n( $ncount ) . "</span>";
- }
- else {
- $ncount = "<span id='bp-awaiting-none' class='pending-count'>0</span>";
- }
- $wp_admin_bar->add_menu( array( 'id' => $idbp, 'title' => sprintf( __('%s'), $ncount ) , 'href' => $bp->loggedin_user->domain ) );
- if ( $notifications ) {
- $counter = 0;
- for ( $i = 0; $i < count($notifications); $i++ ) {
- $wp_admin_bar->add_menu( array( 'parent' => $idbp, 'title' => $notifications[$i], 'href' => $bp->loggedin_user->domain ) );
- $counter++;
- }
- }
- else {
- $wp_admin_bar->add_menu( array( 'parent' => $idbp, 'title' => __('No New Notifications'), 'href' => $bp->loggedin_user->domain ) );
- }
- }
- }
- add_action( 'admin_bar_menu', 'bp_admin_bar_add_notes', 10 );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement