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
)
);
}
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.