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>';

 

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.