lesterchan / wp-useronline

Enable you to display how many users are online on your WordPress blog with detailed statistics.
https://wordpress.org/plugins/wp-useronline/
36 stars 18 forks source link

Just return number from get_users_browsing_page #20

Open bash88 opened 5 years ago

bash88 commented 5 years ago

Hi,

I don't see any way to just return a number from get_users_browsing_page, so I brute forced myself a way to do it. Probably all wrong.

Is this something you could maybe include in the plugin?

lesterchan commented 5 years ago

Maybe try UserOnline_Template::compact_list( 'page', 'list', $page_url ) Code is https://github.com/lesterchan/wp-useronline/blob/master/template-tags.php#L111

bash88 commented 5 years ago

Thank you very much for your quick response!

I went with: count( UserOnline_Template::compact_list( 'page', 'list', '' ) )

Only now it's not updating real-time, right? Is there any way to fix that?

lesterchan commented 5 years ago

Nope. It is totally different. This just basically counts the user at the point in time. If you want real time, you need to write your own AJAX calls to an endpoint that calls that line.

bash88 commented 5 years ago

Well, the real-time update does happen but it switches the output back to html..

<span id="useronline-browsing-page"><strong>2 Bezoekers</strong> Bezoeken deze pagina.<br>Gebruikers: <strong>2 Gasten</strong></span>

lesterchan commented 5 years ago

Just replace this line? https://github.com/lesterchan/wp-useronline/blob/master/core.php#L172

bash88 commented 5 years ago

Awesome, that works. But I'd rather not have custom code in the plugin of course. Do you think you can include this in the plugin? Something like:

users_browsing_page($page_url, $number_only);

Or maybe a global setting to bypass templates and just return numbers?