0

I am creating a custom user role with the code below in functions.php, however WordPress only allows the user to create draft pages, they can't then edit draft pages or publish pages even though I have set the capabilities to true?

Any help is much appreciated!. Thanks in advance.

add_action('admin_init', 'user_custom_roles');

function user_custom_roles() {

        add_role(
        'editor_limited',
        'Editor Limited',
        array(
            'read' => true,
            'edit_pages' => true,
            'edit_posts' => true,
            'edit_published_pages' => true,
            'edit_published_posts' => true,
            'edit_others_pages' => true,
            'edit_others_posts' => true,
            'publish_pages' => true,
            'publish_posts' => true,
            'upload_files' => true,
            'unfiltered_html' => true
        )
    );
}
  • I have used your code it's working fine i am able to publish the page and also update the pages. Please check have you install or implemented the any hook for that – Trilok Aug 1 '18 at 9:22
0

Just add the below code your current active theme. Remove the add_action & functions. Just paste below code

$result = add_role( 'client', __(

'Client' ),

array(

'read' => true,
'edit_pages' => true,
'edit_posts' => true,
'edit_published_pages' => true,
'edit_published_posts' => true,
'edit_others_pages' => true,
'edit_others_posts' => true,
'publish_pages' => true,
'publish_posts' => true,
'upload_files' => true,
'unfiltered_html' => true

)

);
0

Although it's good to know how to edit the code to get the result you want, I prefer to use plugins to do the job, where they are available. This future-proofs the solution, delegating the responsibility to keep up with WordPress updates to the plugin author, rather than to you or your client. So, have you considered the https://en-gb.wordpress.org/plugins/user-role-editor/ plugin? This should be easily configurable to do what you want.

  • I prefer to limit the amount of plugins used for security reasons. – ianhman Aug 1 '18 at 11:14
0

Solved it. The problem was the the custom user capabilities were stuck in the cache. When I changed the capabilities it had not affect. Therefore I had to use the remove_role("editor_limited") command to remove the user role and then add back in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.