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 ) { |
| 2108 | 2108 | * @param string $classname Optional. Classname widget option. Default empty. |
| 2109 | 2109 | * @param mixed ...$params Widget parameters. |
| 2110 | 2110 | */ |
| 2111 | | function register_sidebar_widget($name, $output_callback, $classname = '') { |
| | 2111 | function register_sidebar_widget($name, $output_callback, $classname = '', ...$params) { |
| 2112 | 2112 | _deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_sidebar_widget()' ); |
| 2113 | 2113 | // 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 { |
| 2118 | 2118 | $name = $name[0]; |
| | 2119 | } |
| 2119 | 2120 | } |
| 2120 | 2121 | |
| 2121 | | $id = sanitize_title($name); |
| | 2122 | $id = sanitize_title( $name ); |
| 2122 | 2123 | $options = array(); |
| 2123 | | if ( !empty($classname) && is_string($classname) ) |
| | 2124 | if ( ! empty( $classname ) && is_string( $classname ) ) { |
| 2124 | 2125 | $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 | } |
| 2129 | 2127 | |
| 2130 | | call_user_func_array('wp_register_sidebar_widget', $args); |
| | 2128 | wp_register_sidebar_widget( $id, $name, $output_callback, $options, ...$params ); |
| 2131 | 2129 | } |
| 2132 | 2130 | |
| 2133 | 2131 | /** |
| … |
… |
function unregister_sidebar_widget($id) { |
| 2158 | 2156 | * @deprecated 2.8.0 Use wp_register_widget_control() |
| 2159 | 2157 | * @see wp_register_widget_control() |
| 2160 | 2158 | * |
| 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. |
| 2165 | 2164 | */ |
| 2166 | | function register_widget_control($name, $control_callback, $width = '', $height = '') { |
| | 2165 | function register_widget_control($name, $control_callback, $width = '', $height = '', ...$params) { |
| 2167 | 2166 | _deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_widget_control()' ); |
| 2168 | 2167 | // 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 { |
| 2173 | 2172 | $name = $name[0]; |
| | 2173 | } |
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | | $id = sanitize_title($name); |
| | 2176 | $id = sanitize_title( $name ); |
| 2177 | 2177 | $options = array(); |
| 2178 | | if ( !empty($width) ) |
| | 2178 | if ( ! empty( $width ) ) { |
| 2179 | 2179 | $options['width'] = $width; |
| 2180 | | if ( !empty($height) ) |
| | 2180 | } |
| | 2181 | if ( ! empty( $height ) ) { |
| 2181 | 2182 | $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 | } |
| 2186 | 2184 | |
| 2187 | | call_user_func_array('wp_register_widget_control', $args); |
| | 2185 | wp_register_widget_control( $id, $name, $control_callback, $options, ...$params ); |
| 2188 | 2186 | } |
| 2189 | 2187 | |
| 2190 | 2188 | /** |