From 8669496f96642b2ae75b8abceb0a74e81f993fef Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Wed, 12 Aug 2020 02:37:01 +0200
Subject: [PATCH] PHP 8.0: fix "ArgumentCountError: array_merge() does not
accept unknown named parameters" [1]
As per the documentation of `call_user_func_array()`, the $param_arr` should be a (numerically) indexed array, not a string-keyed array.
As we can use the spread operator in PHP 5.6+, there isn't really any need to use `call_user_func_array()` anyhow, we can call the `array_merge()` function directly.
The caveat to this is that the spread operator only works on numerically indexed arrays, so we need to wrap the `$sidebars_widgets` variable in a call to `array_values()` when using the spread operator.
Using `array_values()` in the existing `call_user_func_array()` call would also have solved this, but the solution now proposed, has the added benefit of getting rid of the overhead of `call_user_func_array()`.
Refs:
* https://www.php.net/manual/en/function.call-user-func-array
* https://www.php.net/manual/en/function.array-merge
* https://www.php.net/manual/en/function.array-values.php
---
src/wp-includes/widgets.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wp-includes/widgets.php b/src/wp-includes/widgets.php
index 6f2701e5ea..0d176687fb 100644
|
a
|
b
|
function retrieve_widgets( $theme_changed = false ) { |
| 1262 | 1262 | $sidebars_widgets = wp_map_sidebars_widgets( $sidebars_widgets ); |
| 1263 | 1263 | |
| 1264 | 1264 | // Find hidden/lost multi-widget instances. |
| 1265 | | $shown_widgets = call_user_func_array( 'array_merge', $sidebars_widgets ); |
| | 1265 | $shown_widgets = array_merge( ...array_values( $sidebars_widgets ) ); |
| 1266 | 1266 | $lost_widgets = array_diff( $registered_widgets_ids, $shown_widgets ); |
| 1267 | 1267 | |
| 1268 | 1268 | foreach ( $lost_widgets as $key => $widget_id ) { |