Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:00:21+00:00 2026-05-27T14:00:21+00:00

I’ve got a quite large website with over 20 roles and permissions. However, it

  • 0

I’ve got a quite large website with over 20 roles and permissions. However, it are always the same permissions, but depending on who created the content, the permissions differ…

So what I do now is this:

    // Make the new role
    $role = new stdClass;
    $role->name = 'Redacteur 1';
    $role->weight = 3;
    user_role_save($role);

    // Permissions to assign to the role.
    // Note these are defined in hook_permission()
    $perms = array(
    'access content','access content overview'
    );

    // Grant the permissions. This function takes care of all necessary cache resets
    user_role_grant_permissions($role->rid, $perms);

    // Make the new role
    $role = new stdClass;
    $role->name = 'Redacteur 2';
    $role->weight = 3;
    user_role_save($role);

    // Permissions to assign to the role.
    // Note these are defined in hook_permission()
    $perms = array(
    'access content','access content overview'
    );

    // Grant the permissions. This function takes care of all necessary cache resets
    user_role_grant_permissions($role->rid, $perms);

Isn’t there a way to do this with some kind of array so I don’t end up with a 1000 line of code. When you want to change something in the permissions, you have to revise all the roles… This must be easier to do. Any advice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:00:22+00:00Added an answer on May 27, 2026 at 2:00 pm

    I wrote some default function to acomplish this goal:

    function _load_permission_settings($role_index = null) {
        // Blocks
        $perms['administer blocks'] =           array(0, 0, 0);
        // Comments
        $perms['administer comments'] =         array(0, 1, 0);
        $perms['access comments'] =             array(1, 1, 1);
        $perms['post comments'] =               array(1, 1, 1);
        $perms['skip comment approval'] =       array(1, 1, 1);
        $perms['edit own comments'] =           array(1, 1, 1);
            ...
    
    
    function _create_users() {
        require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
    
        $roles = user_roles(true);
    
        $users[] = array('an', array(3));
        $users[] = array('ben', array(4, 6, 8));
        ...
    
    function _set_roles_and_permissions() {
        // Enable default permissions for system roles.
        user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));
        user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, _load_permission_settings(0));
    
        // Permissions to assign to the roles. (all Thema-related roles share the same permissions)
        $perms_eind = _load_permission_settings(1);
        $perms_red = _load_permission_settings(2);
    
        $user_roles = _load_thema_user_role_names('');
        foreach ($user_roles as $name) {
            // Role1
                $role = new stdClass;
            $role->name = 'Role 1 - ' . $name;
            user_role_save($role);
            user_role_grant_permissions($role->rid, $perms_eind);
            // Role2
            $role = new stdClass;
            $role->name = 'Role 2 - ' . $name;
            user_role_save($role);
            user_role_grant_permissions($role->rid, $perms_red);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.