• Resolved eyewebdesign

    (@eyewebdesign)


    Hi,

    I made custom user roles with this code:

    add_action('init', 'eye_add_roles');
    function eye_add_roles() {
    	add_role( 'nucinfo user', 'Nucinfo user', get_role( 'administrator' )->capabilities);
    	add_role( 'daness user', 'Daness user', get_role( 'administrator' )->capabilities);
    }

    But when I want to add restrictions with content control and check administrator and a custom role, only the administrator is assigned. I can assign all default roles, but not the custom ones, I can select them but they aren’t added.

    What am I doing wrong?

    Kind regards
    Davy

Viewing 6 replies - 1 through 6 (of 6 total)
  • Bel

    (@belimperial)

    Hi @eyewebdesign

    Thank you for getting in touch.

    It seems the custom code is missing the arrays for the capabilities.

    Something like:

    $result = add_role('nucinfo-user', __(
       'Nucinfo user w/ capabilities'),
       array(
           'read'            => true, // Allows a user to read
           'create_posts'      => true, // Allows user to create new posts
           'edit_posts'        => true, // Allows user to edit their own posts
           'edit_others_posts' => true, // Allows user to edit others posts too
           'publish_posts' => true, // Allows the user to publish posts
           'manage_categories' => true, // Allows user to manage post categories
           )
    );

    You can also use third-party plugins like Roles & Capabilities plugin to duplicate the administrator role with the correct capabilities.

    You can use the duplicate role and configure it according to your needs.

    Assign the newly created custom role to the user profile to make it work on the Content Control settings.

    We hope that helps. Let us know if you have questions.

    Thread Starter eyewebdesign

    (@eyewebdesign)

    Hi,

    I just tested it with the following code, but the problem still occurs.

    add_action('init', 'eye_add_roles');
    function eye_add_roles() {
    	add_role( 'nucinfo user', 'Nucinfo user', array(
           'read'            => true, // Allows a user to read
           'create_posts'      => true, // Allows user to create new posts
           'edit_posts'        => true, // Allows user to edit their own posts
           'edit_others_posts' => true, // Allows user to edit others posts too
           'publish_posts' => true, // Allows the user to publish posts
           'manage_categories' => true, // Allows user to manage post categories
           ));
    	add_role( 'daness user', 'Daness user', array(
           'read'            => true, // Allows a user to read
           'create_posts'      => true, // Allows user to create new posts
           'edit_posts'        => true, // Allows user to edit their own posts
           'edit_others_posts' => true, // Allows user to edit others posts too
           'publish_posts' => true, // Allows the user to publish posts
           'manage_categories' => true, // Allows user to manage post categories
           ));
    }
    Bel

    (@belimperial)

    Hi @eyewebdesign

    Your code for the custom role slug has a space.

    Please see:
    add_role( ‘nucinfo user’
    add_role( ‘daness user’

    Could you try the following?
    – Delete the old roles on your site
    – Add a dash or remove the space for the custom role slug
    – Resave the custom code to apply the new custom roles
    – Create a new user or update the user role of the existing WordPress account to use the new custom role

    Here’s our test:
    https://share.getcloudapp.com/llug9zJq
    https://share.getcloudapp.com/Jruy1Xez
    https://share.getcloudapp.com/o0u9EkKk
    https://share.getcloudapp.com/llug9zXB

    Other hand, kindly note that we don’t have support for custom coding, please have a look at your custom code to ensure it will work properly on Content Control. We hope for your kind understanding.

    We hope that helps. Let us know if you have questions.

    Thread Starter eyewebdesign

    (@eyewebdesign)

    Hi,

    It was indeed the space that did the trick, I replaced it with a _. What a stupid mistake!

    Thanks a lot for your help!

    Kind regards
    Dave

    Plugin Support Kim L

    (@kimmyx)

    Hi Dave,

    Thanks for the update! Let us know if there’s anything else we can assist you with or if we can go ahead and mark this topic as resolved.

    Cheers!

    Thread Starter eyewebdesign

    (@eyewebdesign)

    Hi,

    No, thanks a lot for the excellent support!

    Kind regards
    Davy

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘restrict custom user roles’ is closed to new replies.