2
votes

I'm new at Wordpress plugin creation and still trying to get the concept of action hook or filter hook.

I've created a custom role for "moderator". What I want for this role:
- in charge of users with specific role, e.g. subscribers.
- able to change users password.
- NOT able to change other users roles.

the problem is this: to be able to change other users password the moderators will need to have access to user profile page. But, on the user profile page, the moderators can change the other user role. I'm able to hide it by changing the wp-admin/user-edit.php but I think it's better done by plugin. So, how to hide / modify the "roles" selection with a plugin?

Thanks for the help.

To make it more clear, I'm attaching a picture for it. enter image description here

1

1 Answers

1
votes

There are no hooks to remove that. It has to be solved with CSS and/or jQuery.

Here, both CSS and jQuery do almost the same, you can choose one or another, or use both.

The current_user_can has to be adjusted to your roles/capabilities setup.

Note that the hook admin_head can have a suffix, so it'll only run in that specific /wp-admin/WP-PAGE.php address.

add_action( 'admin_head-user-edit.php', 'so_13598192_remove_roles_dropbox' );

function so_13598192_remove_roles_dropbox()
{
    // Admins can edit that, exit without printing scripts
    if ( current_user_can( 'administrator' ) )
        return;
    ?>
        <style>
            label[for=role], #role
            {
                display:none;
            }
        </style>
        <script>
            jQuery(document).ready(function($)
            {     
                $('label[for=role]').parent().parent().remove();      
            });
        </script>
    <?php
}