1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
// ***************************************************************
// Remove any role that has a capability that the current user doesn't have.
// 
// uses the 'role_names_listing' filter which might not exist yet. Probably
// won't be around until 2.6 is released, maybe 2.5.1...
//

function check_user_editable_roles($role_names) {
	global $wp_roles;
	foreach ($wp_roles->roles as $role => $details) :
		foreach ($details['capabilities'] as $capability => $value) :
			if (!current_user_can($capability)) :
				unset ($role_names[$role]);
				break;
			endif; 
		endforeach; //capabilities
	endforeach; //foreach $wp_roles;
	return $role_names;
}
add_filter('role_names_listing', 'check_user_editable_roles');

?>