list all wordpress roles in selectbox for Admin secion

In your theme code backend or plugin code you can list your wp roles. You need to display wordpress users roles many times in theme configuration and plugins page. For fetching the wp users roles you can use the following code.

If you need to show User roles in theme configuration and plugins page. For list all wordpress roles in selectbox, you can use our code.

list all wordpress roles in selectbox

$roles_obj = new WP_Roles();
$roles_names_array = $roles_obj->get_names();
echo '<select name="role">';
foreach ($roles_names_array as $role_name) {
	echo '<option>'.$role_name.'</option>';
}
echo '</select>';

 

Add a Comment

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