Custom User Role - can't edit or publish pages?

admin2025-01-07  4

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 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
        )
    );
}
Share Improve this question asked Aug 1, 2018 at 9:12 ianhmanianhman 135 bronze badges 1
  • 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 Commented Aug 1, 2018 at 9:22
Add a comment  | 

3 Answers 3

Reset to default 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

)

);

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.

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736258887a547.html

最新回复(0)