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 { |
| 738 | 738 | * @return bool Whether the user has the given capability, or, if an object ID is passed, whether the user has |
| 739 | 739 | * the given capability for that object. |
| 740 | 740 | */ |
| 741 | | public function has_cap( $cap ) { |
| | 741 | public function has_cap( $cap, ...$args ) { |
| 742 | 742 | if ( is_numeric( $cap ) ) { |
| 743 | 743 | _deprecated_argument( __FUNCTION__, '2.0.0', __( 'Usage of user levels is deprecated. Use capabilities instead.' ) ); |
| 744 | 744 | $cap = $this->translate_level_to_cap( $cap ); |
| 745 | 745 | } |
| 746 | 746 | |
| 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 ); |
| 750 | 748 | |
| 751 | 749 | // Multisite super admin has all caps by definition, Unless specifically denied. |
| 752 | 750 | if ( is_multisite() && is_super_admin( $this->ID ) ) { |
| … |
… |
class WP_User { |
| 756 | 754 | return true; |
| 757 | 755 | } |
| 758 | 756 | |
| | 757 | // Maintain BC for the argument passed to the "user_has_cap" filter. |
| | 758 | $args = array_merge( array( $cap, $this->ID ), $args ); |
| | 759 | |
| 759 | 760 | /** |
| 760 | 761 | * Dynamically filter a user's capabilities. |
| 761 | 762 | * |