Skip to content

Instantly share code, notes, and snippets.

@matrixwd
Last active April 20, 2019 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matrixwd/b3118beec0f4d2df1ab6e320b0de4e37 to your computer and use it in GitHub Desktop.
Save matrixwd/b3118beec0f4d2df1ab6e320b0de4e37 to your computer and use it in GitHub Desktop.
Extends the WP Statistics Plugin to show how many users are currently online.
<?php
/*
This gets added to your wordpress themes function.php or as a seperate plugin file
This function extends the WP Statistics Plugin to show how many users are currently online
And links it to the WP Statistics Page.
The css class is added for you to style according to your needs.
Will add future items later.
*/
// adds the link to the WP Toolbar
function custom_toolbar_link($wp_admin_bar) {
// To see more info on user levels https://codex.wordpress.org/Roles_and_Capabilities#User_Level_to_Role_Conversion
if( current_user_can( 'level_3' ) ){
$args = array(
'id' => 'wpstats',
'title' => '<span class="ab-icon dashicons-before dashicons-admin-users"></span><span class="ab-label">'. do_shortcode( "[wpstatistics stat=usersonline]" ) .' Users Currently Online</span>',
'href' => '/wp-admin/admin.php?page=wps_online_page',
'meta' => array(
'class' => 'wpstatsOnline',
'title' => 'See users that are online right now.'
)
);
$wp_admin_bar->add_node($args);
}
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);
@matrixwd
Copy link
Author

This could also be expanded with an admin jquery file to update the count every x seconds. But, I will leave that up to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment