From ae566d2fa10ec389ee6eb28b6d6591d881071497 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 30 Jul 2026 20:39:13 +0530 Subject: [PATCH] Toolbar, Privacy: Use array_key_first() to read the first key of an array. Replace `current( array_keys( $array ) )` with `array_key_first( $array )`. The former builds a complete array of every key only to read the first one and throw the rest away, which costs O(n) time and O(n) memory; `array_key_first()` reads the first bucket directly in constant time and allocates nothing. `wp_admin_bar_new_content_menu()` runs on every admin page load and on every front-end load for logged-in users with the toolbar visible, and its `$actions` array grows with the number of registered post types. `array_key_first()` is available in PHP 7.3 and later, which is below the current minimum supported version. Props mukesh. --- src/wp-admin/includes/privacy-tools.php | 2 +- src/wp-includes/admin-bar.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/privacy-tools.php b/src/wp-admin/includes/privacy-tools.php index e7b949842ffd1..17e660c8c0d0e 100644 --- a/src/wp-admin/includes/privacy-tools.php +++ b/src/wp-admin/includes/privacy-tools.php @@ -74,7 +74,7 @@ function _wp_personal_data_handle_actions() { if ( isset( $_POST['privacy_action_email_retry'] ) ) { check_admin_referer( 'bulk-privacy_requests' ); - $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); + $request_id = absint( array_key_first( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ); $result = _wp_privacy_resend_request( $request_id ); if ( is_wp_error( $result ) ) { diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 99bb122ec4c36..5ba568792209c 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -1080,7 +1080,7 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) { array( 'id' => 'new-content', 'title' => $title, - 'href' => admin_url( current( array_keys( $actions ) ) ), + 'href' => admin_url( array_key_first( $actions ) ), 'meta' => array( 'menu_title' => _x( 'New', 'admin bar menu group label' ), ),