Code Modernisation: Introduce the spread operator in WP_User.

Rather than relying `func_get_args()` to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

Props jrf.
See #47678.

Built from https://develop.svn.wordpress.org/trunk@45623


git-svn-id: http://core.svn.wordpress.org/trunk@45434 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2019-07-11 23:48:56 +00:00
parent 5d658427a8
commit 4de2f2f49b
2 changed files with 6 additions and 5 deletions

View File

@ -738,15 +738,13 @@ class WP_User {
* @return bool Whether the user has the given capability, or, if an object ID is passed, whether the user has * @return bool Whether the user has the given capability, or, if an object ID is passed, whether the user has
* the given capability for that object. * the given capability for that object.
*/ */
public function has_cap( $cap ) { public function has_cap( $cap, ...$args ) {
if ( is_numeric( $cap ) ) { if ( is_numeric( $cap ) ) {
_deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) ); _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) );
$cap = $this->translate_level_to_cap( $cap ); $cap = $this->translate_level_to_cap( $cap );
} }
$args = array_slice( func_get_args(), 1 ); $caps = map_meta_cap( $cap, $this->ID, ...$args );
$args = array_merge( array( $cap, $this->ID ), $args );
$caps = call_user_func_array( 'map_meta_cap', $args );
// Multisite super admin has all caps by definition, Unless specifically denied. // Multisite super admin has all caps by definition, Unless specifically denied.
if ( is_multisite() && is_super_admin( $this->ID ) ) { if ( is_multisite() && is_super_admin( $this->ID ) ) {
@ -756,6 +754,9 @@ class WP_User {
return true; return true;
} }
// Maintain BC for the argument passed to the "user_has_cap" filter.
$args = array_merge( array( $cap, $this->ID ), $args );
/** /**
* Dynamically filter a user's capabilities. * Dynamically filter a user's capabilities.
* *

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-45622'; $wp_version = '5.3-alpha-45623';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.