wp-useronline icon indicating copy to clipboard operation
wp-useronline copied to clipboard

Just return number from get_users_browsing_page

Open bash88 opened this issue 5 years ago • 6 comments

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?

bash88 avatar Aug 27 '19 10:08 bash88

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

lesterchan avatar Aug 27 '19 10:08 lesterchan

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?

bash88 avatar Aug 27 '19 10:08 bash88

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.

lesterchan avatar Aug 27 '19 10:08 lesterchan

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>

bash88 avatar Aug 27 '19 10:08 bash88

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

lesterchan avatar Aug 27 '19 10:08 lesterchan

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?

bash88 avatar Aug 27 '19 10:08 bash88