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.


git-svn-id: https://develop.svn.wordpress.org/trunk@45623 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-07-11 23:47:56 +00:00
parent 50ec358b41
commit 1963a00f83

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
* 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.
*