BuddyDev

Search

[Resolved] Buddypress Unread Message Count

Tagged: , ,

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #17147

    Hello,

    I am trying to show the number of unread messages a user has, but can’t find the code anywhere. Please help 🙂

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2541
    Ravi on #17149

    Hello Mwale,

    Thank you for asking. There is a message function with name “messages_get_unread_count( $user_id = 0 )” it returns unread message count for the user id. Please try this.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #17151

    Hi Ravi,

    Thank you for your reply 🙂

    Unfortunately, that leads to a fatal error ‘undefined function’. I am adding it like so:

    <a id="user-messages" href="/messages/" class="msg">Messages <span class="alert_count"><?php if( class_exists( 'Buddypress' ) ) {echo messages_get_unread_count( $user_id = 0 );} ?></span></a>

  • Keymaster
    (BuddyDev Team)
    Posts: 22510
    Brajesh Singh on #17161

    Hi Mwale,

    1. Please make sure you have BuddyPress Messages component enable where you are trying to use the function.

    2. For fetching current user’s count, you can use

    
    <a id="user-messages" href="/messages/" class="msg">Messages <span class="alert_count"><?php if( class_exists( 'Buddypress' ) ) {echo messages_get_unread_count( get_current_user_id() );} ?></span></a>
    
    

    I do suggest that instead of checking for BuddyPress class, you might want to check function_exists for the above function. That way, if messages component is disabled, it won’t cause fatal error.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #17191

    Hey Brajesh!

    Thank you so much! Everything works fine thanks to you 🙂

    I have also changed the condition to ‘function_exists’, thanks!

    Kind regards,
    Mwale

  • Keymaster
    (BuddyDev Team)
    Posts: 22510
    Brajesh Singh on #17195

    Thank you MWale,

    Glad that it worked.
    Have a great day 🙂

    Regards
    Brajesh

The topic ‘ [Resolved] Buddypress Unread Message Count’ is closed to new replies.

This topic is: resolved