Skip to content

Instantly share code, notes, and snippets.

@hatsumatsu
Last active August 16, 2016 11:50
Show Gist options
  • Save hatsumatsu/834a25fffb19bf006e5e4fc2c4326fde to your computer and use it in GitHub Desktop.
Save hatsumatsu/834a25fffb19bf006e5e4fc2c4326fde to your computer and use it in GitHub Desktop.
/**
* Get the total number of users by user role
*
* Usage:
*
* if( function_exists( 'get_resonate_user_count' ) ) {
* if( $count = get_resonate_user_count( 'my-custom-user-role' ) ) {
* echo sprintf( __( 'My user rule has %s users.' ), $count );
* }
* }
*
* @param string $role role name
* @return int|false total number of users or false
*/
function get_resonate_user_count( $role ) {
if( !$role ) {
return false;
}
$query = new WP_User_Query(
array(
'role' => $role
)
);
if( !$query->get_total() ) {
return false;
}
return $query->get_total();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment