Code Modernisation: Introduce the spread operator in `wp-includes/deprecated.php`.

Rather than relying `func_get_args()` to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

While these functions are deprecated, they can still get a minor performance boost in case they are being called.

Props jrf.
See #47678.
Built from https://develop.svn.wordpress.org/trunk@46129


git-svn-id: http://core.svn.wordpress.org/trunk@45941 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-15 11:09:54 +00:00
parent 6a039a5731
commit efe18c3604
2 changed files with 33 additions and 38 deletions

View File

@ -1798,10 +1798,9 @@ function _nc( $single, $plural, $number, $domain = 'default' ) {
* @deprecated 2.8.0 Use _n()
* @see _n()
*/
function __ngettext() {
function __ngettext( ...$args ) {
_deprecated_function( __FUNCTION__, '2.8.0', '_n()' );
$args = func_get_args();
return call_user_func_array('_n', $args);
return _n( ...$args );
}
/**
@ -1811,10 +1810,9 @@ function __ngettext() {
* @deprecated 2.8.0 Use _n_noop()
* @see _n_noop()
*/
function __ngettext_noop() {
function __ngettext_noop( ...$args ) {
_deprecated_function( __FUNCTION__, '2.8.0', '_n_noop()' );
$args = func_get_args();
return call_user_func_array('_n_noop', $args);
return _n_noop( ...$args );
}
@ -2076,8 +2074,7 @@ function js_escape( $text ) {
function wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
_deprecated_function( __FUNCTION__, '2.8.0', 'esc_html()' );
if ( func_num_args() > 1 ) { // Maintain back-compat for people passing additional arguments.
$args = func_get_args();
return call_user_func_array( '_wp_specialchars', $args );
return _wp_specialchars( $string, $quote_style, $charset, $double_encode );
} else {
return esc_html( $string );
}
@ -2117,26 +2114,24 @@ function attribute_escape( $text ) {
* @param string $classname Optional. Classname widget option. Default empty.
* @param mixed ...$params Widget parameters.
*/
function register_sidebar_widget($name, $output_callback, $classname = '') {
function register_sidebar_widget($name, $output_callback, $classname = '', ...$params) {
_deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_sidebar_widget()' );
// Compat
if ( is_array($name) ) {
if ( count($name) == 3 )
$name = sprintf($name[0], $name[2]);
else
if ( is_array( $name ) ) {
if ( count( $name ) === 3 ) {
$name = sprintf( $name[0], $name[2] );
} else {
$name = $name[0];
}
}
$id = sanitize_title($name);
$id = sanitize_title( $name );
$options = array();
if ( !empty($classname) && is_string($classname) )
if ( ! empty( $classname ) && is_string( $classname ) ) {
$options['classname'] = $classname;
$params = array_slice(func_get_args(), 2);
$args = array($id, $name, $output_callback, $options);
if ( !empty($params) )
$args = array_merge($args, $params);
}
call_user_func_array('wp_register_sidebar_widget', $args);
wp_register_sidebar_widget( $id, $name, $output_callback, $options, ...$params );
}
/**
@ -2167,33 +2162,33 @@ function unregister_sidebar_widget($id) {
* @deprecated 2.8.0 Use wp_register_widget_control()
* @see wp_register_widget_control()
*
* @param int|string $name Sidebar ID.
* @param callable $control_callback Widget control callback to display and process form.
* @param int $width Widget width.
* @param int $height Widget height.
* @param int|string $name Sidebar ID.
* @param callable $control_callback Widget control callback to display and process form.
* @param int $width Widget width.
* @param int $height Widget height.
* @param mixed ...$params Widget parameters.
*/
function register_widget_control($name, $control_callback, $width = '', $height = '') {
function register_widget_control($name, $control_callback, $width = '', $height = '', ...$params) {
_deprecated_function( __FUNCTION__, '2.8.0', 'wp_register_widget_control()' );
// Compat
if ( is_array($name) ) {
if ( count($name) == 3 )
$name = sprintf($name[0], $name[2]);
else
if ( is_array( $name ) ) {
if ( count( $name ) === 3 ) {
$name = sprintf( $name[0], $name[2] );
} else {
$name = $name[0];
}
}
$id = sanitize_title($name);
$id = sanitize_title( $name );
$options = array();
if ( !empty($width) )
if ( ! empty( $width ) ) {
$options['width'] = $width;
if ( !empty($height) )
}
if ( ! empty( $height ) ) {
$options['height'] = $height;
$params = array_slice(func_get_args(), 4);
$args = array($id, $name, $control_callback, $options);
if ( !empty($params) )
$args = array_merge($args, $params);
}
call_user_func_array('wp_register_widget_control', $args);
wp_register_widget_control( $id, $name, $control_callback, $options, ...$params );
}
/**

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-46128';
$wp_version = '5.3-alpha-46129';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.