WordPress.org

Make WordPress Core

Ticket #47678: 47678-user_can.patch

File 47678-user_can.patch, 1.2 KB (added by jrf, 8 months ago)

Simplify & modernize user_can()

  • src/wp-includes/capabilities.php

    From ea0369944f6d23d084e5d3f11195f5db66efebd6 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Thu, 11 Jul 2019 11:17:47 +0200
    Subject: [PATCH] Simplify & modernize user_can()
    
    ---
     src/wp-includes/capabilities.php | 7 ++-----
     1 file changed, 2 insertions(+), 5 deletions(-)
    
    diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php
    index 6c8f76906b..e2d132d217 100644
    a b function author_can( $post, $capability, ...$args ) { 
    754754 * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
    755755 * @return bool Whether the user has the given capability.
    756756 */
    757 function user_can( $user, $capability ) {
     757function user_can( $user, $capability, ...$args ) {
    758758        if ( ! is_object( $user ) ) {
    759759                $user = get_userdata( $user );
    760760        }
    function user_can( $user, $capability ) { 
    763763                return false;
    764764        }
    765765
    766         $args = array_slice( func_get_args(), 2 );
    767         $args = array_merge( array( $capability ), $args );
    768 
    769         return call_user_func_array( array( $user, 'has_cap' ), $args );
     766        return $user->has_cap( $capability, ...$args );
    770767}
    771768
    772769/**