WordPress.org

Make WordPress Core

Ticket #47678: 47678-current_user_can_for_blog.patch

File 47678-current_user_can_for_blog.patch, 1.4 KB (added by jrf, 8 months ago)

Simplify & modernize current_user_can_for_blog()

  • src/wp-includes/capabilities.php

    From d91c273679218269e1c318cc11eaab293ab37f2a Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Thu, 11 Jul 2019 11:10:55 +0200
    Subject: [PATCH] Simplify & modernize current_user_can_for_blog()
    
    ---
     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 c9c91848c2..44f3debf20 100644
    a b function current_user_can( $capability, ...$args ) { 
    678678 * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
    679679 * @return bool Whether the user has the given capability.
    680680 */
    681 function current_user_can_for_blog( $blog_id, $capability ) {
     681function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
    682682        $switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
    683683
    684684        $current_user = wp_get_current_user();
    function current_user_can_for_blog( $blog_id, $capability ) { 
    690690                return false;
    691691        }
    692692
    693         $args = array_slice( func_get_args(), 2 );
    694         $args = array_merge( array( $capability ), $args );
    695 
    696         $can = call_user_func_array( array( $current_user, 'has_cap' ), $args );
     693        $can = $current_user->has_cap( $capability, ...$args );
    697694
    698695        if ( $switched ) {
    699696                restore_current_blog();