Skip to content

Commit 64d4a6d

Browse files
Coding Standards: Use array_first() to get the first array element.
This replaces `array_values( ... )[0]` and `array_slice( ..., 0, 1 )[0]` constructs with the `array_first()` function added in PHP 8.5 for improved readability. WordPress core includes a polyfill for `array_first()` on PHP < 8.5 as of WordPress 6.9, so the change works on every supported PHP version without raising the minimum requirement. Follow-up to [9685], [50995], [60672]. Props Soean, mukesh27. See #65598. git-svn-id: https://develop.svn.wordpress.org/trunk@62695 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 99fc144 commit 64d4a6d

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

src/wp-includes/class-wp-walker.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ public function walk( $elements, $max_depth, ...$args ) {
234234
*/
235235
if ( empty( $top_level_elements ) ) {
236236

237-
$first = array_slice( $elements, 0, 1 );
238-
$root = $first[0];
237+
$root = array_first( $elements );
239238

240239
$top_level_elements = array();
241240
$children_elements = array();

src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public function encode_form_data( $request ) {
504504
isset( $request['form_data'][ "widget-$id" ] ) &&
505505
is_array( $request['form_data'][ "widget-$id" ] )
506506
) {
507-
$new_instance = array_values( $request['form_data'][ "widget-$id" ] )[0];
507+
$new_instance = array_first( $request['form_data'][ "widget-$id" ] );
508508
$old_instance = $instance;
509509

510510
$instance = $widget_object->update( $new_instance, $old_instance );

0 commit comments

Comments
 (0)