Make WordPress Core

Changeset 45623


Ignore:
Timestamp:
07/11/2019 11:47:56 PM (5 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-user.php

    r45590 r45623  
    739739     *              the given capability for that object.
    740740     */
    741     public function has_cap( $cap ) {
     741    public function has_cap( $cap, ...$args ) {
    742742        if ( is_numeric( $cap ) ) {
    743743            _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) );
     
    745745        }
    746746
    747         $args = array_slice( func_get_args(), 1 );
    748         $args = array_merge( array( $cap, $this->ID ), $args );
    749         $caps = call_user_func_array( 'map_meta_cap', $args );
     747        $caps = map_meta_cap( $cap, $this->ID, ...$args );
    750748
    751749        // Multisite super admin has all caps by definition, Unless specifically denied.
     
    756754            return true;
    757755        }
     756
     757        // Maintain BC for the argument passed to the "user_has_cap" filter.
     758        $args = array_merge( array( $cap, $this->ID ), $args );
    758759
    759760        /**
Note: See TracChangeset for help on using the changeset viewer.