[wp-trac] [WordPress Trac] #53131: Disjunctive normal form for WP_User::has_cap

WordPress Trac noreply at wordpress.org
Wed May 19 01:17:43 UTC 2021


#53131: Disjunctive normal form for WP_User::has_cap
-----------------------------+------------------------------
 Reporter:  manfcarlo        |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Users            |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by manfcarlo):

 Replying to [comment:4 peterwilsoncc]:

 When I opened the ticket, I just wanted to "pitch" the idea in the
 simplest way possible, but I was kind of aware that it would be backward
 incompatible. Plugins that use the `map_meta_cap` filter expect an array
 of strings, so I don't think it could be implemented through the existing
 filter.

 However, I wonder if it could be achieved by adding a second filter. For
 example:

 {{{#!php
 <?php
 $strings = apply_filters( 'map_meta_cap', $strings );

 $dnf = apply_filters( 'map_meta_cap_arrays', array( $strings ) );

 // Now user must have ALL from ANY set in $dnf
 }}}

 I believe that disjunctive normal form can be alternatively expressed as
 conjunctive normal form, so the following could be an alternative
 implementation:

 {{{#!php
 <?php
 $strings = apply_filters( 'map_meta_cap', $strings );

 $cnf = array();

 foreach ( $strings as $string ) {
     $cnf[] = apply_filters( 'map_meta_cap_strings', array( $string ) );
 }

 // Now user must have ANY from ALL sets in $cnf
 }}}

 These are just ideas off the top of my head, so it's entirely possible
 there are other issues with these suggested implementations.

 For example, which of the two filters should run first and which should
 run second? Should the output of the first filter be passed into the
 second filter, or should they run separately and be combined at the end?
 These kinds of implications would have to be considered, so as not to
 unexpectedly change the behaviour of existing plugins.

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


More information about the wp-trac mailing list