WordPress.org

Make WordPress Core

Ticket #47678: 47678-WP_User-has_cap.patch

File 47678-WP_User-has_cap.patch, 1.6 KB (added by jrf, 8 months ago)

Simplify & modernize WP_User::has_cap()

  • src/wp-includes/class-wp-user.php

    From 6b117ae8b4ff8c29993702ae9a52b2716093f267 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Thu, 11 Jul 2019 11:37:36 +0200
    Subject: [PATCH] Simplify & modernize WP_User::has_cap()
    
    ---
     src/wp-includes/class-wp-user.php | 9 +++++----
     1 file changed, 5 insertions(+), 4 deletions(-)
    
    diff --git a/src/wp-includes/class-wp-user.php b/src/wp-includes/class-wp-user.php
    index f4bb9b12c8..73f7cdf0d5 100644
    a b class WP_User { 
    738738         * @return bool Whether the user has the given capability, or, if an object ID is passed, whether the user has
    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.' ) );
    744744                        $cap = $this->translate_level_to_cap( $cap );
    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.
    752750                if ( is_multisite() && is_super_admin( $this->ID ) ) {
    class WP_User { 
    756754                        return true;
    757755                }
    758756
     757                // Maintain BC for the argument passed to the "user_has_cap" filter.
     758                $args = array_merge( array( $cap, $this->ID ), $args );
     759
    759760                /**
    760761                 * Dynamically filter a user's capabilities.
    761762                 *