[wp-trac] [WordPress Trac] #51254: includes/plugin.php remove_menu_page should check if $menu is array
WordPress Trac
noreply at wordpress.org
Sat Sep 5 14:49:44 UTC 2020
#51254: includes/plugin.php remove_menu_page should check if $menu is array
--------------------------+-----------------------------
Reporter: kernelzechs | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Depending on when remove_menu_page is executed global $menu many not be
populated (mind you this shouldn't happen when using the correct hooks,
but should be handled regardless), as a result can lead to warnings in
PHP. A check should be added here to prevent an issue. The original code
and proposed solution are below:
**Old Code:**
{{{#!php
<?php
function remove_menu_page( $menu_slug ) {
global $menu;
foreach ( $menu as $i => $item ) {
if ( $menu_slug == $item[2] ) {
unset( $menu[ $i ] );
return $item;
}
}
return false;
}
}}}
**New Code:**
{{{#!php
<?php
function remove_menu_page( $menu_slug ) {
global $menu;
// Empty check not required, type check only should suffice.
if (is_array($menu)) {
foreach ( $menu as $i => $item ) {
if ( $menu_slug == $item[2] ) {
unset( $menu[ $i ] );
return $item;
}
}
}
return false;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51254>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list