Edit "Roles" drop box on User Profile
-
Hi,
I have set a custom role for a “moderator” where the guy can help other users to change name / password, but I don’t want this guy to be able to change users role.
So, if the moderator login, the “Roles” drop down box on user profile, will contain only the roles that I want, or perhaps hiding it altogether.
Instead of changing the code directly at wp-admin/user-edit.php I think it’s better to build a plugin. But I can’t seem to find a hook or action or filter, etc that can done that.
I’m thinking this is the code on user-edit.php that I need to change, but I prefer using plugin, so I just post this to give you clear example what I want to do
<?php if ( !IS_PROFILE_PAGE && !is_network_admin() && $curr_login_is_admin) : ?> <tr><th><label for="role"><?php _e('Role:') ?></label></th> <td><select name="role" id="role"> <?php // Get the highest/primary role for this user // TODO: create a function that does this: wp_get_user_role() $user_roles = $profileuser->roles; $user_role = array_shift($user_roles); // print the full list of roles with the primary one selected. wp_dropdown_roles($user_role); // print the 'no role' option. Make it selected if the user has no role yet. if ( $user_role ) echo '<option value="">' . __('— No role for this site —') . '</option>'; else echo '<option value="" selected="selected">' . __('— No role for this site —') . '</option>'; ?> </select></td></tr> <?php endif; //!IS_PROFILE_PAGE
I also already tried building a plugin like this, but it’s not working, it’s being called too late.
`
add_action(‘show_user_profile’, ‘jawbet_permission’,1);
add_action(‘edit_user_profile’, ‘jawbet_permission’,1);function jawbet_permission() {
echo “I’m here.\n”;global $wp_roles;
$all_roles = $wp_roles->roles;
$tmp=array();$keys=array();$values=array();
foreach($all_roles as $key=>$value)
if($key!=’editor’){
array_push($keys,$key);
array_push($values,$value);
}
for ($i=0;$i<count($keys);$i++){
$tmp[$keys[$i]]=$values[$i];
}
$wp_roles->roles=$tmp;
wp_dropdown_roles($user_role);
}
`Help please. Thanks.
- The topic ‘Edit "Roles" drop box on User Profile’ is closed to new replies.