WordPress.org

Make WordPress Core

Ticket #47678: 47678-__call.patch

File 47678-__call.patch, 4.8 KB (added by jrf, 7 months ago)

Simplify & modernize *::call() The callback in these functions is always checked against a limited list of valid callbacks and those are not problematic, so these can be safely changed to dynamic function calls.

  • src/wp-admin/includes/class-wp-list-table.php

    From 51700c716f3898578434f3097252ffb91a22ea48 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sat, 20 Jul 2019 18:14:07 +0200
    Subject: [PATCH] Simplify & modernize *::__call()
    
    The callback in these functions is always checked against a limited list of valid callbacks and those are not problematic, so these can be safely changed to dynamic function calls.
    ---
     src/wp-admin/includes/class-wp-list-table.php | 2 +-
     src/wp-includes/class-wp-comment-query.php    | 2 +-
     src/wp-includes/class-wp-oembed.php           | 2 +-
     src/wp-includes/class-wp-query.php            | 2 +-
     src/wp-includes/class-wp-roles.php            | 2 +-
     src/wp-includes/class-wp-user-query.php       | 2 +-
     src/wp-includes/class-wp-user.php             | 2 +-
     src/wp-includes/class-wp-xmlrpc-server.php    | 2 +-
     8 files changed, 8 insertions(+), 8 deletions(-)
    
    diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php
    index 021547fd18..0994e197ea 100644
    a b class WP_List_Table { 
    239239         */
    240240        public function __call( $name, $arguments ) {
    241241                if ( in_array( $name, $this->compat_methods ) ) {
    242                         return call_user_func_array( array( $this, $name ), $arguments );
     242                        return $this->$name( ...$arguments );
    243243                }
    244244                return false;
    245245        }
  • src/wp-includes/class-wp-comment-query.php

    diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php
    index eba9ddf54e..7e055fc1b1 100644
    a b class WP_Comment_Query { 
    124124         */
    125125        public function __call( $name, $arguments ) {
    126126                if ( 'get_search_sql' === $name ) {
    127                         return call_user_func_array( array( $this, $name ), $arguments );
     127                        return $this->get_search_sql( ...$arguments );
    128128                }
    129129                return false;
    130130        }
  • src/wp-includes/class-wp-oembed.php

    diff --git a/src/wp-includes/class-wp-oembed.php b/src/wp-includes/class-wp-oembed.php
    index dce67fcb41..ffbdb45b0e 100644
    a b class WP_oEmbed { 
    235235         */
    236236        public function __call( $name, $arguments ) {
    237237                if ( in_array( $name, $this->compat_methods ) ) {
    238                         return call_user_func_array( array( $this, $name ), $arguments );
     238                        return $this->$name( ...$arguments );
    239239                }
    240240                return false;
    241241        }
  • src/wp-includes/class-wp-query.php

    diff --git a/src/wp-includes/class-wp-query.php b/src/wp-includes/class-wp-query.php
    index 3d7374cf93..6da6909a86 100644
    a b class WP_Query { 
    35603560         */
    35613561        public function __call( $name, $arguments ) {
    35623562                if ( in_array( $name, $this->compat_methods ) ) {
    3563                         return call_user_func_array( array( $this, $name ), $arguments );
     3563                        return $this->$name( ...$arguments );
    35643564                }
    35653565                return false;
    35663566        }
  • src/wp-includes/class-wp-roles.php

    diff --git a/src/wp-includes/class-wp-roles.php b/src/wp-includes/class-wp-roles.php
    index 18b0d55035..6e3004c37c 100644
    a b class WP_Roles { 
    101101         */
    102102        public function __call( $name, $arguments ) {
    103103                if ( '_init' === $name ) {
    104                         return call_user_func_array( array( $this, $name ), $arguments );
     104                        return $this->_init( ...$arguments );
    105105                }
    106106                return false;
    107107        }
  • src/wp-includes/class-wp-user-query.php

    diff --git a/src/wp-includes/class-wp-user-query.php b/src/wp-includes/class-wp-user-query.php
    index 33408e51d0..56a0dce6bd 100644
    a b class WP_User_Query { 
    885885         */
    886886        public function __call( $name, $arguments ) {
    887887                if ( 'get_search_sql' === $name ) {
    888                         return call_user_func_array( array( $this, $name ), $arguments );
     888                        return $this->get_search_sql( ...$arguments );
    889889                }
    890890                return false;
    891891        }
  • src/wp-includes/class-wp-user.php

    diff --git a/src/wp-includes/class-wp-user.php b/src/wp-includes/class-wp-user.php
    index 73f7cdf0d5..a1c2b6e2c4 100644
    a b class WP_User { 
    444444         */
    445445        public function __call( $name, $arguments ) {
    446446                if ( '_init_caps' === $name ) {
    447                         return call_user_func_array( array( $this, $name ), $arguments );
     447                        return $this->_init_caps( ...$arguments );
    448448                }
    449449                return false;
    450450        }
  • src/wp-includes/class-wp-xmlrpc-server.php

    diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php
    index 72aeef2048..8dfc737231 100644
    a b class wp_xmlrpc_server extends IXR_Server { 
    177177         */
    178178        public function __call( $name, $arguments ) {
    179179                if ( '_multisite_getUsersBlogs' === $name ) {
    180                         return call_user_func_array( array( $this, $name ), $arguments );
     180                        return $this->_multisite_getUsersBlogs( ...$arguments );
    181181                }
    182182                return false;
    183183        }