Make WordPress Core

Changeset 63297


Ignore:
Timestamp:
08/14/2026 07:47:01 AM (8 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.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r62662 r63297  
    7575                check_admin_referer( 'bulk-privacy_requests' );
    7676
    77                 $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) );
     77                $request_id = absint( array_key_first( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) );
    7878                $result     = _wp_privacy_resend_request( $request_id );
    7979
  • 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.