This is my script which lists all the roles...
function all_the__roles() {
global $wp_roles;
$the_roles = $wp_roles->get_names();
$roles = '';
$role_count = '';
foreach($the_roles as $role) {
$roles .= $role . '<br />';
$role_count++;
}
return $roles;
}
echo all_the__roles();
If I change return $roles;
to return $role_count;
then I get the number of roles.
Is there a way I can have both without writing an additional separate function? I want to list the roles and also the number roles. So the output could be something like:
Administrator
Editor
Client
3
Cheers.
', $the_roles )` or `count($the_roles)` etc. And then there is no reason making a function for it. Otherwise do `return ['roles' => implode('
', $the_roles ), 'count' => count($the_roles)]` and remove the `foreach` -6 lines of code. – ArtisticPhoenix Mar 09 '19 at 09:39