If you are the only person controlling your whole website, you have probably never had to think about WordPress users and their roles. However, if you ever want to give other people access to your WordPress website, WordPress user roles are essential for managing what actions the various users at your site are allowed to take.
WordPress user roles determine what actions each user at your site is authorized to perform. These actions are called capabilities. In this article, we are going to show how to list WordPress users by their user role.
WordPress has some pre-defined user roles :
- Super Admin
- Administrator
- Editor
- Author
- Subscriber
- Contributor
Here is the code to display the list of users, by their Specific Roles. We can also delete these default User Roles if not required for the website.
In the below array we have given the user role as “subscriber” so it will make the list of users who is having the role “Subscriber” with their E-mail.
</pre> $args = array( 'role' => 'Subscriber', 'orderby' => 'user_nicename', 'order' => 'ASC' ); $users = get_users( $args ); echo '<ul>'; foreach ( $users as $user ) { echo '<li>' . esc_html( $user->display_name ) . '[' . esc_html( $user->user_email ) . ']</li>'; } echo '</ul>'; <pre>
Happy Coding 🙂
Add Comment