Make WordPress Core


Ignore:
Timestamp:
08/14/2026 07:47:01 AM (11 hours ago)
Author:
westonruter
Message:

Code Modernization: Use array_key_first() for an array's first key.

current( array_keys( $array ) ) builds a complete array of every key only to read the first one and discard the rest, whereas array_key_first() reads the first bucket directly. The function has been native since PHP 7.3, below the current minimum supported version, and core already uses it in wp_replace_in_html_tags(). Behavior is unchanged: the toolbar's $actions cannot be empty at that point, and in the privacy tools absint() normalizes null and false alike.

Developed in https://github.com/WordPress/wordpress-develop/pull/12785.
Follow-up to r18788, r42986.

Props mukesh27, soean.
Fixes #65773.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r62625 r63297  
    10811081                        'id'    => 'new-content',
    10821082                        'title' => $title,
    1083                         'href'  => admin_url( current( array_keys( $actions ) ) ),
     1083                        'href'  => admin_url( array_key_first( $actions ) ),
    10841084                        'meta'  => array(
    10851085                                'menu_title' => _x( 'New', 'admin bar menu group label' ),
Note: See TracChangeset for help on using the changeset viewer.