WordPress.org

Ready to get started?Download WordPress

Forums

Add a Custom Role Based on Default Role (1 post)

  1. Getzel Rubashkin
    Member
    Posted 3 years ago #

    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');
    if($admin->capabilities){
    	foreach($admin->capabilities as $cap => $bool){
                    if($bool){
    		     $general_admin->add_cap($cap);
                    }
    	}
    }

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by Getzel Rubashkin
  • This topic is not resolved
  • WordPress version: 3.1.3