Code Modernisation: Introduce the spread operator in capabilities.php
.
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@45622 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
620704320e
commit
50ec358b41
@ -33,8 +33,7 @@
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return array Actual capabilities for meta capability.
|
||||
*/
|
||||
function map_meta_cap( $cap, $user_id ) {
|
||||
$args = array_slice( func_get_args(), 2 );
|
||||
function map_meta_cap( $cap, $user_id, ...$args ) {
|
||||
$caps = array();
|
||||
|
||||
switch ( $cap ) {
|
||||
@ -649,17 +648,14 @@ function map_meta_cap( $cap, $user_id ) {
|
||||
* @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
|
||||
* passed, whether the current user has the given meta capability for the given object.
|
||||
*/
|
||||
function current_user_can( $capability ) {
|
||||
function current_user_can( $capability, ...$args ) {
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
if ( empty( $current_user ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$args = array_slice( func_get_args(), 1 );
|
||||
$args = array_merge( array( $capability ), $args );
|
||||
|
||||
return call_user_func_array( array( $current_user, 'has_cap' ), $args );
|
||||
return $current_user->has_cap( $capability, ...$args );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -682,7 +678,7 @@ function current_user_can( $capability ) {
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the user has the given capability.
|
||||
*/
|
||||
function current_user_can_for_blog( $blog_id, $capability ) {
|
||||
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
|
||||
$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
@ -694,10 +690,7 @@ function current_user_can_for_blog( $blog_id, $capability ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$args = array_slice( func_get_args(), 2 );
|
||||
$args = array_merge( array( $capability ), $args );
|
||||
|
||||
$can = call_user_func_array( array( $current_user, 'has_cap' ), $args );
|
||||
$can = $current_user->has_cap( $capability, ...$args );
|
||||
|
||||
if ( $switched ) {
|
||||
restore_current_blog();
|
||||
@ -726,7 +719,7 @@ function current_user_can_for_blog( $blog_id, $capability ) {
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the post author has the given capability.
|
||||
*/
|
||||
function author_can( $post, $capability ) {
|
||||
function author_can( $post, $capability, ...$args ) {
|
||||
$post = get_post( $post );
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
@ -738,10 +731,7 @@ function author_can( $post, $capability ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$args = array_slice( func_get_args(), 2 );
|
||||
$args = array_merge( array( $capability ), $args );
|
||||
|
||||
return call_user_func_array( array( $author, 'has_cap' ), $args );
|
||||
return $author->has_cap( $capability, ...$args );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -764,7 +754,7 @@ function author_can( $post, $capability ) {
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the user has the given capability.
|
||||
*/
|
||||
function user_can( $user, $capability ) {
|
||||
function user_can( $user, $capability, ...$args ) {
|
||||
if ( ! is_object( $user ) ) {
|
||||
$user = get_userdata( $user );
|
||||
}
|
||||
@ -773,10 +763,7 @@ function user_can( $user, $capability ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$args = array_slice( func_get_args(), 2 );
|
||||
$args = array_merge( array( $capability ), $args );
|
||||
|
||||
return call_user_func_array( array( $user, 'has_cap' ), $args );
|
||||
return $user->has_cap( $capability, ...$args );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user