Buddypress Unread Messages - Current Update?

I use the following code to display the number of unread messages of registered users in the template.

<?php if (messages_get_unread_count() != 0) { ?> <div id="message_count"> <div class="countspan"> <?php echo messages_get_unread_count(); ?> </div> </div> <?php } ?> 

This works great, but a page refresh is required for updating. Since I actively use ajax-driven navigation throughout the site and the user applications in it, this is not a satisfactory solution.

How to automatically update the counter?

I played with the "lvive notifications" plugin, which checks srver every 10 seconds to provide live notifications, but of course this does not interact with my custom unread message count.

Any ideas guys? I really could take help.

+4
source share
3 answers

I dealt with this ...

It turns out that buddypress built a lot of things in ajax functions ...

So, for those who want to do the same ... This is a simple case to put an β€œaccount” inside a link with the following identifier.

  <a id="user-messages"> <span><?php echo messages_get_unread_count(); ?></span> </a> 

Buddypress' javascript then does the rest for you. Plain!

Mana thanks for your suggestion.

+5
source

You can use setTimeout to periodically run a request to the server that calls your messages_get_unread_count() and returns a value.

Then, based on the return value, you can show or hide your <div id="message_count"> with the updated counter.

+2
source

You can do this with jQuery, which calls a separate php file, for example.

jQuery.post ('call.php', {action: "get"}, function (data) {

  jQuery('#content').append(data); }); 

In this tutorial, you will review it http://vavumi.com/?p=257

+1
source

All Articles