2

I've created a new user role called "writer" and assigned him the following capabilities.

read, 
edit_post ,
upload_files, 
edit_posts, 
edit_published_posts,
publish_posts,
level_0,
level_1,
level_2`

The user can upload images but cannot edit the media details like title, caption etc. non editable media file details

The text boxes are read only. Am I missing a permission in the user role?

Edit: the code for the role is:

add_role( 'writer', 'Writer', array(
    'read'=>true,
    'edit_post'=>true,
    'upload_files'=>true,
    'edit_posts'=>true,
    'edit_published_posts'=> true,
    'publish_posts'=>true,
    'level_0'=>true,
    'level_1'=>true,
    'level_2'=>true
    )
 );

Edit: Found it. Somehow adding the capability "edit_others_posts" fixed the issue.

6
  • Please could you add the complete code of the function for this role so we can see where maybe some went wrong? – Charles Aug 27 '17 at 6:44
  • @Charles added the code as requested. – Prasun Jajodia Aug 27 '17 at 7:00
  • First some minor notes: be consequent when coding. Meaning by that, do not use single and/or double quote mix in your code as shown (and done by you). Secondly what are those level_* do in the code, what are they meant for? Third did you check the codex? – Charles Aug 27 '17 at 8:03
  • @Charles. The inconsistency was due to debugging and adding different capabilities and will be corrected. The level_* was experimentally added in the end after reviewing the level of 'author' from the codex who is allowed to edit media details. I got it using the code $role = get_role('author');foreach( $role->capabilities as $name => $val ){echo $name . "<br />";} . I did check the codex, but couldn't find anything on media description editing – Prasun Jajodia Aug 27 '17 at 8:08
  • Found it. Somehow adding the capability "edit_others_posts" fixed the issue. – Prasun Jajodia Aug 27 '17 at 9:13
1

As mentioned in my comment(s), below the code as it imho should be.(tested and working)

/**
 * Add new role: Writer
 * This role allows to: Add/Edit/Delete Posts and Uploads
 *
 * Read more: {@link https://codex.wordpress.org/Roles_and_Capabilities}
 *
 * Works with @version WP4.8.1 and below
 */
add_role( 'writer', 'Writer', 
    array( 
        'delete_posts'           => true,
        'delete_published_posts' => true,
        'edit_posts'             => true,
        'edit_published_posts'   => true,
        'publish_posts'          => true,
        'read'                   => true,
        'upload_files'           => true, 
        )
    );

Add the code in functions.php and please remove it after it is added/visible in the Back-end(Admin panel) because it will be add to your database. Else WP will try to add the role (although already done) every visit from every user all the time. (Useless and a bad habit in this case)

Just as note, please read the Codex so you understand what I tried to explain.
Adjust (delete unneeded code) to your own preferences.

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.