[wp-trac] [WordPress Trac] #47678: Modernize/simplify current_user_can()

WordPress Trac noreply at wordpress.org
Mon Jul 15 18:47: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:24 pento]:
 > There are [https://github.com/search?q=org%3Awp-
 plugins+%22extends+walker%22&type=Code ~260 instances] of `extend Walker`
 here, but presumably more in themes, custom plugins, etc.

 I've reviewed the first 100 results and only two of these overload the
 `walk()` method.
 * [https://github.com/wp-
 plugins/polylang/blob/72f6116b15ccabf987741e32ff219553babdf9f9/include
 /walker-dropdown.php#L60 Polylang]
 * [https://github.com/wp-plugins/thoughtful-
 comments/blob/657b85426e233580d601381e7c03b2e2fba0d8dd/walkers.php#L122
 Thoughtful Comments]

 All the others just overload the `start_el()`, `start_lvl()`, `end_el()`
 and/or `end_lvl()` methods, just like the WP Core native child classes do.

 A [https://github.com/search?l=&q=org:wp-
 plugins+%22extends+Walker%22+%22function+walk%28%22+language:PHP&type=Code
 little more specific search] yields 26 results out of which 16 are still
 false positives or tagged version duplicates and only 10 actually 1)
 extend one of the `Walker` classes and 2) overload the `walk()` method.
 Those 10 files are in the following 8 plugins:
 * Polylang (2x)
 * Thoughful Comments (1x)
 * Another WordPress Classifieds Plugin (1x)
 * BuddyPress (1x)
 * Extended Categories Widget (2x)
 * Page Menu Widget (1x)
 * WP Sitemanager (1x)
 * Custom Menu Wizard (1x)

 So, while it does happen, it is extremely rare (8 plugins out of 80.000+).


 > I think this change could still work, in combination with a dev-note,
 and an easy pattern for plugin authors to maintain back compat with old
 versions of WordPress.

 Maintaining back-compat with older versions of WP is not a problem.
 Overloaded methods are perfectly okay to have ''more'' parameters than the
 parent method. See: https://3v4l.org/P1PaI

 The only issue would be that they wouldn't be able to still support older
 PHP versions. They would ''have'' to update their minimum supported PHP
 version to 5.6+ to use the spread operator.


 And while we've now just looked at `Walker::walk()`, the same principle
 applies to the other `public` methods where the signature changed. Though
 I expect that, for any of those to be overloaded, would be even more rare
 than the overloading of `Walker::walk()`.

 Changed WP Core classes:
 * `WP:User::has_cap()`
 * `Walker::walk()` (reverted in [45640])
 * `Walker::paged_walk()`
 * `wpdb::prepare()`

 And in the WP unit test classes:
 * `WP_UnitTestCase_Base::assertQueryTrue()`
 * `MockAction::filterall()`
 * `Tests_WP_Customize_Manager::capture_customize_post_value_set_actions()`
 * `Tests_WP_Hook_Do_Action::_action_callback()`

 And the tools class:
 * `NotGettexted::logmsg()`

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


More information about the wp-trac mailing list