From 73d11c9822580fc477a842b89e449391b8a14860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20W=C3=BCnsch?= Date: Mon, 6 Jul 2026 14:15:03 +0200 Subject: [PATCH] Coding Standards: Use array_first() to get the first array element. Replace `array_values( ... )[0]` and `array_slice( ..., 0, 1 )[0]` constructs with the `array_first()` function (added in PHP 8.5, polyfilled in compat.php) for improved readability. --- src/wp-includes/class-wp-walker.php | 3 +-- .../endpoints/class-wp-rest-widget-types-controller.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-walker.php b/src/wp-includes/class-wp-walker.php index df67921c2746c..7361520cbdccc 100644 --- a/src/wp-includes/class-wp-walker.php +++ b/src/wp-includes/class-wp-walker.php @@ -234,8 +234,7 @@ public function walk( $elements, $max_depth, ...$args ) { */ if ( empty( $top_level_elements ) ) { - $first = array_slice( $elements, 0, 1 ); - $root = $first[0]; + $root = array_first( $elements ); $top_level_elements = array(); $children_elements = array(); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php index 4208ad2d922ba..1d07c27251c3b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php @@ -504,7 +504,7 @@ public function encode_form_data( $request ) { isset( $request['form_data'][ "widget-$id" ] ) && is_array( $request['form_data'][ "widget-$id" ] ) ) { - $new_instance = array_values( $request['form_data'][ "widget-$id" ] )[0]; + $new_instance = array_first( $request['form_data'][ "widget-$id" ] ); $old_instance = $instance; $instance = $widget_object->update( $new_instance, $old_instance );