[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 Aug 8 18:25:33 UTC 2023


#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 hellofromTonya):

 The code in the `foreach` was introduced in [8691] over 15 years ago:
 {{{#!php
 // 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 =
 classes.
 foreach ( $submenu_items as $sub_key => $sub_item ) {
    if ( ! current_user_can( $sub_item[1] ) ) {
 }}}

 I wonder: Why would the capability element be missing in the `$sub_item`?

 Adding defensive code before attempting to access it is good, but can hide
 a potential problem. I'm hesitant to move forward with
 [https://github.com/WordPress/wordpress-develop/pull/3140 the patch]
 without first understanding the root cause.

 Seems this code is expecting the format identified which includes the
 capability element being at index `1`.

 I'm wondering ..
 * Should sub items always be an array with element `1` as the capability?
 * Are there checks or set up of the array structure where the menu is
 created, i.e. executing before the above code runs?
 * If yes, then this is likely a plugin or theme doing it wrong?

 The answers will take investigation.

 @pras88in more information is needed for contributors like me to
 investigate:

 * Can you share the steps of how to reproduce the issue?

 * Can you share the backtrace call stack given with the PHP error? Copy
 and paste the full error message here.

 * After deactivating all of the plugins, does the issue go away? If yes,
 then one or more of the plugins is the issue. You can reactivate each
 plugin one-by-one to discover which is causing the problem. Then report
 the issue to the plugin author.

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


More information about the wp-trac mailing list