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/src/wp-includes/class-wp-user.php
+++ b/src/wp-includes/class-wp-user.php
@@ -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.
 		 *
-- 
2.21.0.windows.1

