Make WordPress Core

Opened 21 months ago

Last modified 9 months ago

#56254 new defect (bug)

PHP Warning: Undefined array key 1 wp-admin\menu-header.php on line 202

Reported by: pras88in's profile pras.88in Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Administration Keywords: php81 has-patch needs-unit-tests
Focuses: Cc:

Description

i get the above warning when i use php version 8.1.6 in iis server,for php7.427 the code works , am using wordpress 6.0.1 released on jul 12 2022, am unable to fix it , kindly support , i get this error after succesfull login as admimistrator in plugin.php page , and other admin pages.

Change History (5)

#1 @sabernhardt
20 months ago

  • Component changed from General to Administration
  • Keywords php81 added

Hi and welcome to Trac!

If you want site support, the support forums would be a better place to ask:
https://wordpress.org/support/forums/

However, I'll leave this ticket open for now. The undefined key is the user capability needed to display a sub-menu item in the side admin menu, and maybe the condition needs to check whether the key is set/non-empty before using current_user_can().

Last edited 20 months ago by sabernhardt (previous) (diff)

This ticket was mentioned in PR #3140 on WordPress/wordpress-develop by Tabrisrp.


20 months ago
#2

  • Keywords has-patch added

Check for non-empty array key 1 before using it with current_user_can() to avoid PHP warning

Trac ticket: https://core.trac.wordpress.org/ticket/56254

#3 @desrosj
19 months ago

  • Keywords needs-unit-tests added
  • Version trunk deleted

Adding needs-unit-tests since some were requested in the PR.

#4 @hellofromTonya
9 months ago

The code in the foreach was introduced in [8691] over 15 years ago:

// 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 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.

#5 @hellofromTonya
9 months ago

Is this issue an incompatibility with PHP 8.1?

I don't think there's enough information to know if this is an issue in Core. Thus, I'm not adding the php-compatibility focus to list it in exclusions of PHP 8.1 compatibility.

Note: See TracTickets for help on using tickets.