Skip to:
Content
Pages
Categories
Search
Top
Bottom

"New Friendship Request" and "New Message" Notification


  • Alphaaffe
    Participant

    @alphaaffe

    Hi there,

    I’m using the following Code to show users unread messages and pending friend requests in the sidebar:
    Friendship Requests
    Freundschaftsanfragen: <?php echo bp_friend_total_requests_count() ?>
    Unread Messages
    Nachrichten: <?php bp_total_unread_messages_count() ?>
    (I’m using “Enhanced Text Widget” to show php-code in my sidebar-widget)

    Additionally, I want to create some kind of notification that displays users if they have new messages or requests and thtat is only shown IF there are any new messages or requests!

    I imagine it should look something like:
    if (unread messages > 0)
    echo “You have unread Messages”;
    else
    echo ” “;

    if (pending friendship requests > 0)
    echo “You have new friendship requests”;
    else
    echo ” “;

    my problem is, that I don’t know the names of the variables to use (I tried it with the functions instead of the variables which didn’t work). Can anyone of your pls help? I’m using the “allow PHP in posts and pages” plugin to use php in posts and pages^^

    My WordPress-Version is 4.0.1, my Buddypress-Version is 2.1.1

    My website is still under construction and has directory protection, which is why I won’t post the domain, username or password. If your realy need this information, I’ll send it to your via pm.

    P.S. English is not my native language, I apologize for any typos or other kind of misstake.

Viewing 2 replies - 1 through 2 (of 2 total)

  • shanebp
    Moderator

    @shanebp

    As you know bp_total_unread_messages_count() will echo the count.
    Many BP functions have a version that just returns a variable.
    In your case, here they are:

    if (bp_get_total_unread_messages_count( bp_loggedin_user_id() ) > 0 )
    //etc
    
    if (bp_friend_get_total_requests_count( bp_loggedin_user_id() ) > 0 )
    //etc

    Alphaaffe
    Participant

    @alphaaffe

    Hi shanebp,
    that worked perfectly, thanks 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘"New Friendship Request" and "New Message" Notification’ is closed to new replies.
Skip to toolbar