Skip to:
Content
Pages
Categories
Search
Top
Bottom

Notification count in dynamic menu


  • transmission
    Participant

    @transmission

    Hi,
    I am using the new (?) dynamic menus to link to a users profile, messages etc. I would like to show a notification count in the menu, next to where it says “min profil”. Does anyone know a simple way to do this. Thanks in advance for any help/pointers.

    rt

Viewing 1 replies (of 1 total)

  • danbp
    Participant

    @danbp

    Hi @transmission,

    this is not the solution, but an example for your inspiration.
    The below shows how the notification counter can be moved/implemented on the toolbar.

    /* moving the notification counter from right to left */
    remove_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );
    function bpfr_notification_ontheleft() {
    	global $wp_admin_bar;
    	
    	if ( !is_user_logged_in() )
    	return false;
    	
    	$notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
    	$count         = !empty( $notifications ) ? count( $notifications ) : 0;
    	$alert_class   = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
    	$menu_title    = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . $count . '</span>';
    	
    	// Add the top-level Notifications button
    	$wp_admin_bar->add_menu( array(
     /*'parent'    => 'top-secondary',*/  // this is the original position
    	'id'        => 'bp-notifications',
    	'title'     => $menu_title,
    	'href'      => bp_loggedin_user_domain(),
    	) );
    	
    	if ( !empty( $notifications ) ) {
    		foreach ( (array) $notifications as $notification ) {
    			$wp_admin_bar->add_menu( array(
    			'parent' => 'bp-notifications',
    			'id'     => 'notification-' . $notification->id,
    			'title'  => $notification->content,
    			'href'   => $notification->href
    			) );
    		}
    	} else {
    		$wp_admin_bar->add_menu( array(
    		'parent' => 'bp-notifications',
    		'id'     => 'no-notifications',
    		'title'  => __( 'No new notifications', 'buddypress' ),
    		'href'   => bp_loggedin_user_domain()
    		) );
    	}
    	
    	return;
    }
    add_action( 'admin_bar_menu', 'bpfr_notification_ontheleft',30);
    /* other position # are 10, 20, 40, 50, 60, 70, 80, 90 */

    In your case, you also have to check this Codex page. And possibly do some research here.

Viewing 1 replies (of 1 total)
  • The topic ‘Notification count in dynamic menu’ is closed to new replies.
Skip to toolbar