[wp-trac] [WordPress Trac] #54572: Add a function for updating the existing role instead of removing, then adding one

WordPress Trac noreply at wordpress.org
Mon Oct 10 22:08:42 UTC 2022


#54572: Add a function for updating the existing role instead of removing, then
adding one
-------------------------------------------------+-------------------------
 Reporter:  maksimkuzmin                         |       Owner:
                                                 |  davidbaumwald
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  6.1
Component:  Role/Capability                      |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests needs-dev-  |     Focuses:
  note                                           |
-------------------------------------------------+-------------------------

Comment (by manfcarlo):

 Replying to [comment:27 davidbaumwald]:
 > A lot of the validation checks are just the way core does things.
 Countless functions in core accept a variety of input parameters then
 validate and convert them to a single type for processing inside the
 function.  Also, with the changes in PHP 8 type checking is all the more
 important.

 The type checking (e.g. `is_string`) is fine. It is the explicit allowing
 of `null` to indicate the intention to leave unchanged that introduces the
 PHP "undefined offset" errors. I also think it is not very expressive and
 offers little benefit in this particular case.

 {{{#!php
 <?php
 update_role( $role_name, null, $caps );
 }}}

 Rather than talking vaguely about "countless functions in core," can you
 point to a specific precedent that allows the same pattern?

 If not, what about keeping the method but requiring all three parameters
 to be supplied as the correct types?

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


More information about the wp-trac mailing list