Last active
April 20, 2019 04:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.