WordPress.org

Make WordPress Core

Ticket #47678: 47678-author_can.patch

File 47678-author_can.patch, 1.2 KB (added by jrf, 12 months ago)

Simplify & modernize author_can()

  • src/wp-includes/capabilities.php

    From 436597a470d1fc786e571bc0ca531fd3da06e6e6 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Thu, 11 Jul 2019 11:12:30 +0200
    Subject: [PATCH] Simplify & modernize author_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 44f3debf20..6c8f76906b 100644
    a b function current_user_can_for_blog( $blog_id, $capability, ...$args ) { 
    719719 * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
    720720 * @return bool Whether the post author has the given capability.
    721721 */
    722 function author_can( $post, $capability ) {
     722function author_can( $post, $capability, ...$args ) {
    723723        $post = get_post( $post );
    724724        if ( ! $post ) {
    725725                return false;
    function author_can( $post, $capability ) { 
    731731                return false;
    732732        }
    733733
    734         $args = array_slice( func_get_args(), 2 );
    735         $args = array_merge( array( $capability ), $args );
    736 
    737         return call_user_func_array( array( $author, 'has_cap' ), $args );
     734        return $author->has_cap( $capability, ...$args );
    738735}
    739736
    740737/**