From 4de2f2f49b38b6b541a767ff5650d36a5596d07e Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 11 Jul 2019 23:48:56 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-user.php | 9 +++++---- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp-user.php b/wp-includes/class-wp-user.php index f4bb9b12c8..73f7cdf0d5 100644 --- a/wp-includes/class-wp-user.php +++ b/wp-includes/class-wp-user.php @@ -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 * the given capability for that object. */ - public function has_cap( $cap ) { + public function has_cap( $cap, ...$args ) { if ( is_numeric( $cap ) ) { _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) ); $cap = $this->translate_level_to_cap( $cap ); } - $args = array_slice( func_get_args(), 1 ); - $args = array_merge( array( $cap, $this->ID ), $args ); - $caps = call_user_func_array( 'map_meta_cap', $args ); + $caps = map_meta_cap( $cap, $this->ID, ...$args ); // Multisite super admin has all caps by definition, Unless specifically denied. if ( is_multisite() && is_super_admin( $this->ID ) ) { @@ -756,6 +754,9 @@ class WP_User { 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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index e50a4c0689..01562a51f1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.