[wp-trac] [WordPress Trac] #56254: PHP Warning: Undefined array key 1 wp-admin\menu-header.php on line 202

WordPress Trac noreply at wordpress.org
Tue Apr 7 06:25:20 UTC 2026


#56254: PHP Warning:  Undefined array key 1 wp-admin\menu-header.php on line 202
----------------------------------------------+----------------------------
 Reporter:  pras.88in                         |       Owner:  (none)
     Type:  defect (bug)                      |      Status:  new
 Priority:  normal                            |   Milestone:  Awaiting
                                              |  Review
Component:  Administration                    |     Version:
 Severity:  normal                            |  Resolution:
 Keywords:  php81 has-patch needs-unit-tests  |     Focuses:
----------------------------------------------+----------------------------

Comment (by lakshyajeet):

 == Reproduction Report

 === Description
 This report validates whether the issue described in Trac #56254 can be
 reproduced.

 === Environment
 - WordPress: 7.1-alpha-62161-src
 - PHP: 8.3.30
 - Server: nginx/1.29.7
 - Database: mysqli (Server: 8.4.8 / Client: mysqlnd 8.3.30)
 - Browser: Chrome 146.0.0.0
 - OS: macOS
 - Theme: Twenty Twenty-Five 1.4
 - MU Plugins: None activated
 - Plugins: None activated

 === Steps to Reproduce
 1. Install and activate the plugin below.
 2. Log in as an administrator and navigate to any wp-admin page.
 3. Observe the PHP warning in the debug log or on screen.

 === Minimal Reproduction Code

 {{{#!php
 <?php
 /**
  * Plugin Name: Reproduce Trac #56254
  */

 add_action( 'admin_menu', 'r56254_register_menus' );

 function r56254_register_menus(): void {
     add_menu_page(
         'Reproduce #56254',          // page title
         'Reproduce #56254',          // menu title
         'manage_options',            // capability
         'reproduce-56254',           // menu slug
         'r56254_page_callback',      // callback
         'dashicons-warning',         // icon
         80                           // position
     );

     add_submenu_page(
         'reproduce-56254',
         'Good Submenu',
         'Good Submenu',
         'manage_options',            // capability present
         'reproduce-56254-good',
         'r56254_page_callback'
     );

     // Malformed submenu - missing capability
     global $submenu;

     // The array structure core expects: [title, capability, slug,
 page_title]
     // We deliberately omit index 1 (capability) to trigger the warning.
     $submenu['reproduce-56254'][] = [
         0 => 'Broken Submenu',   // menu title
         // 1 => capability       - INTENTIONALLY MISSING (triggers the
 bug)
         2 => 'reproduce-56254-broken',  // slug
         3 => 'Broken Submenu',          // page title
     ];
 }

 function r56254_page_callback(): void {
     echo '<div class="wrap"><h1>Reproduce Trac #56254</h1></div>';
 }

 }}}

 === Actual Results
 1.  ✅ Error condition occurs (reproduced).

 === Additional Notes
 - The warning is reproducible, but this may be expected behavior on the
 core side. `add_submenu_page()` enforces a non-empty capability as a
 required parameter, meaning the `$sub_item[1]` slot is always populated
 under normal usage. The missing key only appears when a plugin or theme
 bypasses the API and writes directly into the global `$submenu` array with
 a malformed entry. This suggests the root cause likely lives in a third-
 party plugin rather than in WordPress core. The defensive guard proposed
 in PR would still be a reasonable hardening measure, but the underlying
 fault is arguably the misbehaving plugin.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56254#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list