BuddyDev

Search

[Resolved] BuddyPress Live Notification

  • Participant
    Level: Initiated
    Posts: 1
    D on #7170

    I’ve added the counter along with font awesome for Friends count and Message counts to the WP admin bar. How can I make the live notification update the message counts and friend counts, separate from the Buddypress actual Notification.

    https://buddydev.com/support/forums/topic/show-new-notification-without-having-to-refresh/

    Code Example:

    function messages_admin_bar_notice( $wp_admin_bar ) {
    if ( !is_user_logged_in() )
    return false;

    $messages = bp_get_total_unread_messages_count( bp_loggedin_user_id() );
    $count = ! empty( $messages ) ? count( $messages ) : 0;
    $alert_class = (int) $count > 0 ? ‘pending-count alert’ : ‘count no-alert’;
    $menu_title = ‘<span id=”ab-pending-notifications” class=”‘ . $alert_class . ‘”>’ . number_format_i18n( $count ) . ‘</span>’;

    $user_domain = bp_loggedin_user_domain();
    $item_link = trailingslashit( $user_domain . ‘messages/’ );
    $args = array(
    ‘id’ => ‘message-notice’,
    ‘parent’ => ‘top-secondary’,
    ‘title’ => $menu_title,
    ‘href’ => $user_domain .’messages/’
    );
    $wp_admin_bar->add_node( $args );
    }
    add_action( ‘admin_bar_menu’, ‘messages_admin_bar_notice’,200 );

    THIS IS THE EXAMPLE CURRENTLY IN USE:

    function messages_admin_bar_notice( $wp_admin_bar ) {
    if ( !is_user_logged_in() )
    return false;
    $messages = bp_get_total_unread_messages_count( bp_loggedin_user_id() );
    $count = !empty( $messages ) ? count( $messages ) : 0;
    $alert_class = (int) $count > 0 ? ‘pending-count alert’ : ‘count no-alert’;
    $user_domain = bp_loggedin_user_domain();
    $item_link = trailingslashit( $user_domain . ‘messages/’ );
    $args = array(
    ‘id’ => ‘message-notice’,
    ‘parent’ => ‘top-secondary’,
    ‘meta’ => array( ‘class’ => $alert_class ),
    ‘title’ => ‘<div class=”bubble”>’. bp_get_total_unread_messages_count( bp_loggedin_user_id() ) .'</div>’,
    ‘href’ => $user_domain .’messages/’
    );
    $wp_admin_bar->add_node( $args );
    }
    add_action( ‘admin_bar_menu’, ‘messages_admin_bar_notice’,200 );

  • Participant
    Level: Initiated
    Posts: 1
    D on #7172

    Got it. Using the second code example separate the bubble div to mess-bubble and fri-bubble
    update css div’s and add calls in bpln.js

    jq( document ).on(‘bpln:new_notifications’, function(evt, data ){

    if( data.count && data.count>0 ){

    update_count_text( jq(‘#ab-pending-notifications’), data.count );

    update_count_text( jq(‘#fri-bubble’), data.count );//THIS
    update_count_text( jq(‘#mess-bubble’), data.count );//THIS

  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #7179

    Hi D,
    Thank you.
    I am glad that you have it resolved 🙂

The topic ‘ [Resolved] BuddyPress Live Notification’ is closed to new replies.

This topic is: resolved