List All User Roles in WordPress

List All User Roles in WordPress

? The Snippet:

$userRoles = new WP_Roles();
$roles_names = $userRoles->get_names();
// Loop through all WP User Roles
foreach ($roles_names as $role_name) {
    echo $role_name . '<br />';
}

ℹ️ About the Snippet

If you ever want to list all user roles in WordPress. Then, you can do this with the above-mentioned small code snippet. It’ll retrieve all the available user roles which include the default and registered user roles.

✅ How to use the Snippet

Add the below code snippet to wherever you want to show all the available WordPress user roles, and this will show all of those.

$userRoles = new WP_Roles();
$roles_names = $userRoles->get_names();
// Loop through all WP User Roles
foreach ($roles_names as $role_name) {
    echo $role_name . '<br />';
}

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get regular WordPress updates directly in your inbox.

shares