[wp-trac] [WordPress Trac] #28605: Introduce customize capability for accessing Customizer

WordPress Trac noreply at wordpress.org
Wed Jul 9 22:20:05 UTC 2014


#28605: Introduce customize capability for accessing Customizer
-----------------------------------+------------------
 Reporter:  westonruter            |       Owner:
     Type:  enhancement            |      Status:  new
 Priority:  normal                 |   Milestone:  4.0
Component:  Customize              |     Version:  3.4
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+------------------

Comment (by westonruter):

 In [attachment:28605.1.diff]:

  * Undo addition of primitive `customize` cap.
  * Add `customize` to `map_meta_cap`. Props nacin.
  * Add missed cap replacement of `edit_theme_options` => `customize`.
  * Run `wp_customize_support_script()` if can customize not
 edit_theme_options.
  * Promote Customize admin menu to top level if user cannot appearance
 cap.
  * Direct non-`edit_theme_options` users from customize to Dashboard if no
 return param available.

 As for how plugins can allow users to access the Customizer now, say for
 any user who can `edit_posts`, a filter can be added for `map_meta_cap`:

 {{{#!php
 function allow_users_who_can_edit_posts_to_customize( $caps, $cap,
 $user_id ) {
         $required_cap = 'edit_posts';
         if ( 'customize' === $cap && user_can( $user_id, $required_cap ) )
 {
                 $caps = array( $required_cap );
         }
         return $caps;
 }
 add_filter( 'map_meta_cap', 'allow_users_who_can_edit_posts_to_customize',
 10, 3 );
 }}}

 Or via the `user_has_cap` filter:

 {{{#!php
 function allow_users_who_can_edit_posts_to_customize( $allcaps, $caps,
 $args ) {
         if ( ! empty( $allcaps['edit_posts'] ) && ! empty( $args ) &&
 'customize' === $args[0] ) {
                 $allcaps = array_merge( $allcaps, array_fill_keys( $caps,
 true ) );
         }
         return $allcaps;
 }
 add_filter( 'user_has_cap', 'allow_users_who_can_edit_posts_to_customize',
 10, 3 );
 }}}

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


More information about the wp-trac mailing list