From fd05ea0de9a826085a383f68b42c8f45a50aa4f4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 15 Sep 2019 11:40:08 +0000 Subject: [PATCH] Code Modernisation: Replace `call_user_func_array()` in `wp-admin/includes/widgets.php` and associated unit tests with a direct function call. Props jrf. See #47678. git-svn-id: https://develop.svn.wordpress.org/trunk@46138 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/widgets.php | 13 +++++++------ tests/phpunit/tests/widgets.php | 28 +++++++++++++--------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/wp-admin/includes/widgets.php b/src/wp-admin/includes/widgets.php index 6eae360c30..9f7dfb573f 100644 --- a/src/wp-admin/includes/widgets.php +++ b/src/wp-admin/includes/widgets.php @@ -51,13 +51,13 @@ function wp_list_widgets() { } } - $args = wp_list_widget_controls_dynamic_sidebar( - array( - 0 => $args, - 1 => $widget['params'][0], - ) + $control_args = array( + 0 => $args, + 1 => $widget['params'][0], ); - call_user_func_array( 'wp_widget_control', $args ); + $sidebar_args = wp_list_widget_controls_dynamic_sidebar( $control_args ); + + wp_widget_control( ...$sidebar_args ); } } @@ -144,6 +144,7 @@ function wp_list_widget_controls_dynamic_sidebar( $params ) { $params[0]['after_widget'] = ''; $params[0]['before_title'] = '%BEG_OF_TITLE%'; // deprecated $params[0]['after_title'] = '%END_OF_TITLE%'; // deprecated + if ( is_callable( $wp_registered_widgets[ $widget_id ]['callback'] ) ) { $wp_registered_widgets[ $widget_id ]['_callback'] = $wp_registered_widgets[ $widget_id ]['callback']; $wp_registered_widgets[ $widget_id ]['callback'] = 'wp_widget_control'; diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index 8e38b30a60..9d5f547dc6 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -620,21 +620,20 @@ class Tests_Widgets extends WP_UnitTestCase { wp_widgets_init(); require_once ABSPATH . '/wp-admin/includes/widgets.php'; - $widget_id = 'search-2'; - $widget = $wp_registered_widgets[ $widget_id ]; - $params = array( + $widget_id = 'search-2'; + $widget = $wp_registered_widgets[ $widget_id ]; + $params = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], ); - $args = wp_list_widget_controls_dynamic_sidebar( - array( - 0 => $params, - 1 => $widget['params'][0], - ) + $control_args = array( + 0 => $params, + 1 => $widget['params'][0], ); + $sidebar_args = wp_list_widget_controls_dynamic_sidebar( $control_args ); ob_start(); - call_user_func_array( 'wp_widget_control', $args ); + wp_widget_control( ...$sidebar_args ); $control = ob_get_clean(); $this->assertNotEmpty( $control ); @@ -659,15 +658,14 @@ class Tests_Widgets extends WP_UnitTestCase { 'after_widget_content' => '', ); $params = array_merge( $params, $param_overrides ); - $args = wp_list_widget_controls_dynamic_sidebar( - array( - 0 => $params, - 1 => $widget['params'][0], - ) + $control_args = array( + 0 => $params, + 1 => $widget['params'][0], ); + $sidebar_args = wp_list_widget_controls_dynamic_sidebar( $control_args ); ob_start(); - call_user_func_array( 'wp_widget_control', $args ); + wp_widget_control( ...$sidebar_args ); $control = ob_get_clean(); $this->assertNotEmpty( $control ); $this->assertNotContains( '
', $control );