WP-UserOnline Shortcode

Below, you’ll find a detailed guide on how to add the WP-UserOnline Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP-UserOnline Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the WP-UserOnline Plugin and the shortcodes it provides:

Plugin Icon
WP-UserOnline

"WP-UserOnline is a WordPress plugin designed to display the number of users currently online on your site. It's a great tool for boosting community engagement and interaction."

★★★★☆ (37) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [page_useronline]

WP-UserOnline [page_useronline] Shortcode

The WP-UserOnline shortcode is used to display the number of users currently online on a WordPress site. It sorts online users into categories (users, members, guests, bots) and displays the count for each. It also shows the highest recorded user count.

Shortcode: [page_useronline]

Examples and Usage

Basic example – Displays the users online on a specific page using the shortcode.

[page_useronline]

PHP Function Code

In case you have difficulties debugging what causing issues with [page_useronline] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'page_useronline', 'users_online_page' );

Shortcode PHP function:

function users_online_page() {
	global $wpdb;

	$usersonline = $wpdb->get_results( "SELECT * FROM $wpdb->useronline ORDER BY timestamp DESC" );

	$user_buckets = array();
	foreach ( $usersonline as $useronline )
		$user_buckets[$useronline->user_type][] = $useronline;

	$user_buckets = apply_filters( 'useronline_buckets', $user_buckets );

	$counts = UserOnline_Template::get_counts( $user_buckets );

	$nicetexts = array();
	foreach ( array( 'user', 'member', 'guest', 'bot' ) as $user_type )
		$nicetexts[$user_type] = UserOnline_Template::format_count( $counts[$user_type], $user_type );

	$text = _n(
		'There is <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>.',
		'There are a total of <strong>%s</strong> online now: <strong>%s</strong>, <strong>%s</strong> and <strong>%s</strong>.',
		$counts['user'], 'wp-useronline'
	);

	$output =
	html( 'div id="useronline-details"',
		 html( 'p', vsprintf( $text, $nicetexts ) )
		.html( 'p', UserOnline_Template::format_most_users() )
		.UserOnline_Template::detailed_list( $counts, $user_buckets, $nicetexts )
	);

	return apply_filters( 'useronline_page', $output );
}

Code file location:

wp-useronline/wp-useronline/core.php

Conclusion

Now that you’ve learned how to embed the WP-UserOnline Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *