Last active
August 16, 2016 11:50
-
-
Save hatsumatsu/834a25fffb19bf006e5e4fc2c4326fde to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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