0

I have a custom role that is allowed to publish articles (the only role allowed to publish). Everything works as expected except that the role cannot edit slugs. It can press 'edit', type anything, but on save it gets reset.

What permission should I add so this is possible?

1 Answer 1

0

If it's supposed to edit its own post only, make it with author's capabilities. If it should edit posts of other users, as well, make it with editor's capabilities.

Case 1

function wpse_add_your_role() {
    $role = get_role( 'author' );
    if ( ! empty( get_role( 'your_role' ) ) ) { 
        remove_role( 'your_role' );
    }
    add_role( 'your_role', 'Your Role', $role->capabilities );
}
add_action( 'init', 'wpse_add_your_role', 10 );

Case 2

function wpse_add_your_role() {
    $role = get_role( 'editor' );
    if ( ! empty( get_role( 'your_role' ) ) ) { 
        remove_role( 'your_role' );
    }
    add_role( 'your_role', 'Your Role', $role->capabilities );
}
add_action( 'init', 'wpse_add_your_role', 10 );

Code location

In both cases, put the code in current theme's functions.php file. Once the new role is created, remove the code from functions.php, or comment out this line:

// add_action( 'init', 'wpse_add_your_role', 10 );

Final notes

You can fine tune your role, using $role->add_cap() or $role->remove_cap() methods, according to your needs. In case 1, do not remove edit_posts capability. In case 2, do not remove, neither, edit_posts nor edit_others_posts capabilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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