Opened 2 years ago
Last modified 16 months ago
#56254 new defect (bug)
PHP Warning: Undefined array key 1 wp-admin\menu-header.php on line 202
Reported by: | 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)
This ticket was mentioned in PR #3140 on WordPress/wordpress-develop by Tabrisrp.
2 years 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
@
2 years ago
- Keywords needs-unit-tests added
- Version trunk deleted
Adding needs-unit-tests
since some were requested in the PR.
#4
@
16 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.
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()
.