Support » Plugins » Add a Custom Role Based on Default Role

  • I am creating custom role and capability functionality for a plugin and I wanted to have a Business Admin role which would not have access to site management, as well as a General Admin role which would be able to access the business functionality as well as the site management.

    add_role( 'general_admin', 'General Admin');
    $admin = get_role('administrator');
    $general_admin = get_role('general_admin');
    	foreach($admin->capabilities as $cap => $bool){

    add_cap basically adds the new capability to an array stored in $general_admin->capabilities, and adds the new capability to the database. If you are not using the database to store and retrieve roles, I think you can bypass the foreach and just copy the $admin->capabilities into the $general_admin->capabilities.

    You can now add any custom capabilities you would like, or modify the capabilities as you wish.

  • The topic ‘Add a Custom Role Based on Default Role’ is closed to new replies.