简体   繁体   中英

How to remove unwanted roles from admin's “New User” Page?

Basiclly, I must Remove the next roles whenever the admin is creating a new user and clicks on the dropdown menu tu display all the available roles:

  • Contributor
  • Editor
  • Unapproved User
  • Author

It should only display Subscriber and Administrator.

Also I must change the name of Subscriber to something different, where is this code? This problem would seem to me like there was a plugin to it.

To remove a role you can use

<?php remove_role( 'editor'); ?> 

and to rename a role add the following php t your functions.php file

function change_role_name() {
    global $wp_roles;

    if ( ! isset( $wp_roles ) )
    $wp_roles = new WP_Roles();

    //You can replace "administrator" with any other role "editor", "author", "contributor" or "subscriber"...
    $wp_roles->roles['administrator']['name'] = 'Owner';
    $wp_roles->role_names['administrator'] = 'Owner';           
}
add_action('init', 'change_role_name');

(The above is from here

There is a function called remove_role that WordPress has in its PHP API. you use it like this:

<?php remove_role('author'); ?>

author could be replaced with any role you want. The way you want to use this command is different than most WP commands. This is because it removes the role from the DB so any future times, the role is already removed. I would recommend making a custom WP plugin that just removes the roles you want on activation.

WP Plugin Help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM