Edit "Roles" drop box on User Profile (1 post)

  1. mr_zhang
    Posted 3 years ago #


    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">
    // 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.
    // print the 'no role' option. Make it selected if the user has no role yet.
    if ( $user_role )
    	echo '<option value="">' . __('&mdash; No role for this site &mdash;') . '</option>';
    	echo '<option value="" selected="selected">' . __('&mdash; No role for this site &mdash;') . '</option>';
    <?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;
    foreach($all_roles as $key=>$value)
    for ($i=0;$i<count($keys);$i++){

    Help please. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic