How to add custom permissions for WordPress roles

WordPress uses the concept of Roles to give the site owner control over what users can and cannot do on the site. By assigning each user a specific role, a site owner can manage user access to tasks such as writing and editing posts, creating pages, creating categories, moderating comments, managing plugins, managing themes, and managing other users. WordPress has six predefined roles: Super Admin, Administrator, Editor, Author, Contributor, and Subscriber, each with its own set of predefined permissions. But what if you want to give each role its additional custom set of permissions, like having  new users to be able to edit pages? This article will show you how to add custom permissions to WordPress roles.

Configuring custom permissions for WordPress roles

  1. Log in to your WordPress site with an administrator account.
  2. On the Dashboard in the left sidebar, click Appearance, and then click Editor:

  3. On the Theme Editor , select the Theme you want to edit from the dropdown:

  4. The files for this selected theme are listed on the right column under Theme Files. Click on the file named “functions.php”:

  5. Add this code snippet / function at the bottom of your functions.php file:

    $result = add_role( 'new', __( 
    
    'New' ),
    
    array( 
    
    'read' => true, // so users can read
    
    'edit_posts' => false, // so users can edit their own posts
    
    'edit_pages' => true, // so users can edit pages
    
    'edit_others_posts' => false, // so users can edit other author's posts
    
    'create_posts' => false, // so users can create new posts
    
    ) 
    
    );
    
  6. With the above code snippet, you can turn the permission on / off by simple true / false value.

    unfiltered_upload – This capability is not available to any role by default (including Super Admins). The capability needs to be enabled by defining the following constant:

    define( 'ALLOW_UNFILTERED_UPLOADS', true );
Get Managed WordPress Hosting

Article Details

Other Articles in This Category

Show More

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.