WordPress.org

Make WordPress Core

Ticket #47678: 47678-more-select-functions-in-wp-includes-deprecated.patch

File 47678-more-select-functions-in-wp-includes-deprecated.patch, 3.9 KB (added by jrf, 9 months ago)

Simplify & modernize functions in wp-includes/deprecated.php [2] While these functions are deprecated, they can still get a minor performance boost in case they are being called. For these functions I've verified that they are still being called by > 1000 plugins, so IMO boosting their performance a little is warranted.

  • src/wp-includes/deprecated.php

    From 4783a20542e5ba61d12d9bd365f0890127d54f72 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sat, 20 Jul 2019 18:37:08 +0200
    Subject: [PATCH] Simplify & modernize functions in wp-includes/deprecated.php
     [2]
    
    While these functions are deprecated, they can still get a minor performance boost in case they are being called.
    
    For these functions I've verified that they **are** still being called by > 1000 plugins, so IMO boosting their performance a little is warranted.
    ---
     src/wp-includes/deprecated.php | 56 ++++++++++++++++------------------
     1 file changed, 27 insertions(+), 29 deletions(-)
    
    diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php
    index 60926e690c..5a1561d82d 100644
    a b function attribute_escape( $text ) { 
    21082108 * @param string     $classname       Optional. Classname widget option. Default empty.
    21092109 * @param mixed      ...$params       Widget parameters.
    21102110 */
    2111 function register_sidebar_widget($name, $output_callback, $classname = '') {
     2111function register_sidebar_widget($name, $output_callback, $classname = '', ...$params) {
    21122112        _deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_sidebar_widget()' );
    21132113        // Compat
    2114         if ( is_array($name) ) {
    2115                 if ( count($name) == 3 )
    2116                         $name = sprintf($name[0], $name[2]);
    2117                 else
     2114        if ( is_array( $name ) ) {
     2115                if ( count( $name ) === 3 ) {
     2116                        $name = sprintf( $name[0], $name[2] );
     2117                } else {
    21182118                        $name = $name[0];
     2119                }
    21192120        }
    21202121
    2121         $id = sanitize_title($name);
     2122        $id      = sanitize_title( $name );
    21222123        $options = array();
    2123         if ( !empty($classname) && is_string($classname) )
     2124        if ( ! empty( $classname ) && is_string( $classname ) ) {
    21242125                $options['classname'] = $classname;
    2125         $params = array_slice(func_get_args(), 2);
    2126         $args = array($id, $name, $output_callback, $options);
    2127         if ( !empty($params) )
    2128                 $args = array_merge($args, $params);
     2126        }
    21292127
    2130         call_user_func_array('wp_register_sidebar_widget', $args);
     2128        wp_register_sidebar_widget( $id, $name, $output_callback, $options, ...$params );
    21312129}
    21322130
    21332131/**
    function unregister_sidebar_widget($id) { 
    21582156 * @deprecated 2.8.0 Use wp_register_widget_control()
    21592157 * @see wp_register_widget_control()
    21602158 *
    2161  * @param int|string $name Sidebar ID.
    2162  * @param callable $control_callback Widget control callback to display and process form.
    2163  * @param int $width Widget width.
    2164  * @param int $height Widget height.
     2159 * @param int|string $name             Sidebar ID.
     2160 * @param callable   $control_callback Widget control callback to display and process form.
     2161 * @param int        $width            Widget width.
     2162 * @param int        $height           Widget height.
     2163 * @param mixed      ...$params        Widget parameters.
    21652164 */
    2166 function register_widget_control($name, $control_callback, $width = '', $height = '') {
     2165function register_widget_control($name, $control_callback, $width = '', $height = '', ...$params) {
    21672166        _deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_widget_control()' );
    21682167        // Compat
    2169         if ( is_array($name) ) {
    2170                 if ( count($name) == 3 )
    2171                         $name = sprintf($name[0], $name[2]);
    2172                 else
     2168        if ( is_array( $name ) ) {
     2169                if ( count( $name ) === 3 ) {
     2170                        $name = sprintf( $name[0], $name[2] );
     2171                } else {
    21732172                        $name = $name[0];
     2173                }
    21742174        }
    21752175
    2176         $id = sanitize_title($name);
     2176        $id      = sanitize_title( $name );
    21772177        $options = array();
    2178         if ( !empty($width) )
     2178        if ( ! empty( $width ) ) {
    21792179                $options['width'] = $width;
    2180         if ( !empty($height) )
     2180        }
     2181        if ( ! empty( $height ) ) {
    21812182                $options['height'] = $height;
    2182         $params = array_slice(func_get_args(), 4);
    2183         $args = array($id, $name, $control_callback, $options);
    2184         if ( !empty($params) )
    2185                 $args = array_merge($args, $params);
     2183        }
    21862184
    2187         call_user_func_array('wp_register_widget_control', $args);
     2185        wp_register_widget_control( $id, $name, $control_callback, $options, ...$params );
    21882186}
    21892187
    21902188/**