[wp-trac] [WordPress Trac] #19834: More Robust Capabilities for Attachments

WordPress Trac noreply at wordpress.org
Mon Jun 25 09:17:05 UTC 2018


#19834: More Robust Capabilities for Attachments
-----------------------------+------------------------------
 Reporter:  walkinonwat3r    |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Media            |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by pampfelimetten):

 Replying to [comment:19 barrykooij]:
 > I would also really like to see custom capabilities for managing media.
 >
 > In my case I've got a CPT with custom capabilities. The role only has
 permission to view/edit/delete these CPT items, but must also be able to
 manage media items (featured image, but also deleting previous uploaded
 images in the media library). The only option at the moment is granting
 the role access to editing posts, what I don't want to.
 >
 > I've edited @dennisderoo code to let a role manage media items when he
 has the permission to upload files (upload_files):
 >
 > {{{
 > public function fix_media_permissions() {
 >     global $wp_post_types;
 >     $wp_post_types['attachment']->cap->edit_post = 'upload_files';
 >     $wp_post_types['attachment']->cap->delete_posts = 'upload_files';
 > }
 > add_action( 'admin_init',  'fix_media_permissions' );
 > }}}

 I ran into the same problem, and barrykooijs code helped me but it still
 misses a bit: You should also set edit_posts, otherwise you cannot edit
 the attachment meta in the set featured image widget:

 {{{#!php
 <?php
     $wp_post_types['attachment']->cap->edit_posts = 'upload_files';
 }}}

 Its weird, but it works.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/19834#comment:39>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list