[wp-trac] [WordPress Trac] #41332: Introduce dedicated capabilities for managing attachments

WordPress Trac noreply at wordpress.org
Sat Aug 19 12:15:50 UTC 2017


#41332: Introduce dedicated capabilities for managing attachments
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
Component:  Media                                |  Release
 Severity:  normal                               |     Version:
 Keywords:  2nd-opinion granular-capabilities    |  Resolution:
  has-patch has-unit-tests                       |     Focuses:
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * keywords:  2nd-opinion granular-capabilities => 2nd-opinion granular-
     capabilities has-patch has-unit-tests
 * milestone:  Awaiting Review => Future Release


Comment:

 @dlh Great, do you have some proposals (or possibly code already) for how
 you are intending to do this?

 [attachment:41332.diff] is a take on how it could work for attachments. It
 uses a straightforward approach, where the `capability_type` of the post
 type is simply changed to 'attachment', and then these "kind of meta"
 capabilities are granted through a `user_has_cap` hook based on the
 regular 'post' post type capabilities (which are actually the properties
 of each post type's `$cap` object).

 The reason I prefer this approach over using `map_meta_cap()` is that I
 consider these capabilities essential in that, if we were to start
 WordPress development now, they would be primitive capabilities and not be
 mapped at all, similar like post and page capabilities are. Furthermore
 this approach is more simple.

 As you can see, the by far biggest part of the patch are tests: This is
 because I thought it's useful to have a dedicated area for this new kind
 of capability. Now we not only have primitive capabilities and meta
 capabilities, but also these "fake primitive" capabilities that are
 granted through `user_has_cap` ([41268] actually added the first one).
 Therefore there are now similar checks made for those new capabilities in
 `Tests_User_Capabilities::testFakePrimitiveCapsTestsAreCorrect()`. The
 capabilities themselves are available through
 `Tests_User_Capabilities::getFakePrimitiveCapsAndRoles()`. By the way, the
 term "fake primitive" is just the first thing I came up with. There's
 probably a better term for this. These new kind of tests should probably
 committed separately if we agree on doing it, before the actual attachment
 changes for this ticket.

 There are two minor other adjustments in tests as well: In one test, I
 replaced a capability related to the 'post' post type with another one so
 that it doesn't affect the fake primitive 'attachment' capabilities. In
 another test I simply replaced the old capability name for editing
 attachments with the new one.

 @johnbillion What's your thought on this?

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


More information about the wp-trac mailing list