Often when a WordPress site is compromised, the website owner doesn't notice anything strange at first. First a lot of users are created, and it's only later when posts filled with spam are created or existing pages/posts edited. In the time between compromise and creation of spam posts, a website owner might notice an increased number of users. If he has the means to. And that's what this little plugin does.

Show the number of registered WordPress users in At-a-Glance widget

Suppose your WordPress site has two registered users, and every time you log on to your Dashboard, you see "2 users registered" in the At a Glance Dashboard widget. Wouldn't that be nice? When that number increases to three, four, ten, a hundred, then you know something is wrong.

Sweet :)

For my Dutch readers, also see my ITFAQ.nl post Twee handige WordPress filters en actions.

Count WordPress Users plugin

The plugin to count registered WordPress Users is a small, one .php file + one .css file, plugin. It performs one database call (MySQL query) for every page load on WordPress' Dashboard index.php file. It's not perfect yet.

All that really is needed, is a query for the number of users:

	"SELECT COUNT(*) FROM $wpdb->users"

WordPress has the count_users() function for this, the SELECT above is a bit simpler. So let's wrap this in a plugin file.

you don't need an extra plugin for this. You can always copy/paste the relevant code parts into your own site-specific plugin or functions.php file.


if ( ! defined( 'ABSPATH' ) ) {

add_action( 'admin_enqueue_scripts', 'enqueue_admin_style' );
function enqueue_admin_style ( $hook_suffix ) {
if ( "index.php" === $hook_suffix ) {
$plugin = get_plugin_data( __FILE__ );
plugins_url( 'includes/admin-page.css', __FILE__ ),
$plugin[ 'Version' ]

add_action( 'dashboard_glance_items', 'custom_glance_items', 10, 1 );
function custom_glance_items( $items = array() ) {
global $wpdb;
$results = $wpdb->get_var(
"SELECT COUNT(*) FROM $wpdb->users"
if( $results ) {
$items[] = sprintf(
'<span class="%1$s">%2$s</span>',
__( $results . ' users registered', 'wpcount-registered-users' ),
) . "\n";
return $items;

This is the CSS to display a (users) groups Dashicon. Add this to includes/admin-page.css:

#dashboard_right_now .users-count:before {
content: "\f307";

1) don't use this where you expect an arbitrary increasing number of users can register on a daily basis, like a forum or membership site. 2) there seems to be a limit of 6 items in the At a Glance widget. If the it doesn't show up as below, and you already have six items there, try to deactivate a plugin that has its information there.

Once activated, this is how it looks in At a Glance:

Show the number of registered WordPress users in the At-a-Glance widget in the Dashboard
Shows the number of registered WordPress users in the At-a-Glance widget in the Dashboard

Create a Dashboard Widget for this

Unfortunately I can't confirm there is a six items limit in the At a Glance widget, so let's create our own Number of Registered Users widget in WordPress' Dashboard. Here is how to create your own custom Dashboard widget for WordPress.

Simply use the following code as plugin, in a site-specific plugin or theme's functions.php file:


if ( ! defined( 'ABSPATH' ) ) {

add_action( 'wp_dashboard_setup', 'saotn_dashboard_widgets' );
function saotn_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget( 'saotn_widget', 'Number of registered users', 'saotn_dashboard_noru');

function saotn_dashboard_noru() {
echo '<p><span class="dashicons dashicons-groups"> </span> '. saotn_count_users() .'</p>';

function saotn_count_users() {
global $wpdb;
$result = $wpdb->get_var(
"SELECT COUNT(*) FROM $wpdb->users"
if( $result ) {
$output = __("There are ${result} users registered in your WordPress site", "wpcount-registered-users-widget" );
return $output;

And this is what it looks like:

Custom WordPress Dashboard widget showing the number of registered users

See the Dashboard widget API documentation for more information

PS: I'm not in the creating WordPress plugins business. I just like to show you how things are done (or can be done). So don't expect this to be released to the WordPress Plugin Directory. If you decide to use my code for your own plugin, please show some credit :-) There may be errors in the code.



  1. Hi,

    This is very useful for me. But can it display the 5 newest registrants with their avatars?

    Dannie Herdyawan

Comments are closed