[wp-trac] [WordPress Trac] #47678: Modernize/simplify current_user_can()
WordPress Trac
noreply at wordpress.org
Fri Jul 12 12:25:41 UTC 2019
#47678: Modernize/simplify current_user_can()
-------------------------------------+-------------------------------------
Reporter: jrf | Owner: pento
Type: enhancement | Status: assigned
Priority: normal | Milestone: 5.3
Component: Role/Capability | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch has-unit- | Focuses: performance, coding-
tests commit | standards
-------------------------------------+-------------------------------------
Comment (by jrf):
Replying to [comment:22 pento]:
> So, we have a bit of a problem, because PHP doesn't do method
overloading.
>
> Changing the method signature of `Walker::walk()` caused an explosion of
PHP warnings on WordPress.org when I deployed this change. The code still
works as expected, it's just a sub-optimal experience.
>
> Example: https://3v4l.org/2iS9g
Well, PHP does do method overloading, just expects as a minimum the same
(number of) arguments.
There are two choices here:
1. Revert that particular change.
2. Update the method signature for the `walk()` and `paged_walk()` methods
in child classes.
I'm very much in favour of 2. Yes, WP is notorious for its backward-
compatibility, but it's not as if other methods have never received new
arguments if a functional change warranted this or am I mistaken ?
And while this may not be considered a "functional change", all this does
is formalize existing behaviour of the methods ''which child-methods
should already comply with''.
In reality the optional variadic additional arguments to these methods are
not new, they just hadn't been made explicit in the method signature. In
most cases, they already were explicit in the documentation, showing that
there was full awareness that this was only not (yet) formalized because
of the limitations in PHP before 5.6.
I'm very happy & willing to prepare the patch for [2], which should
effectively solve this for Core, though to be honest a quick search did
not yield me any classes in Core which overloaded those particular methods
(so far).
As for userland code which may extend the `Walker` class:
1. I have no clue how often this happens. Clearly something on wp.org
does. @Ipstenu would you be able & willing to see how often `extends [A
-Za-z_]*Walker` occurs in plugin-land code ?
2. A dev-note on Make could alert devs to this early so they can update
their code accordingly, though this would "force" userland plugins/themes
to drop support for PHP < 5.6 - and therefore WP < 5.2 - as well.
Note: ''function calls'' to these methods should not be affected, it is
only classes which extend the `Walker` class (or any of the other touched
classes) **and** overload the particular method which has changed.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47678#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list