[wp-trac] [WordPress Trac] #61962: Admin: remove_menu_page throws PHP warning when $menu is null
WordPress Trac
noreply at wordpress.org
Wed May 21 13:45:59 UTC 2025
#61962: Admin: remove_menu_page throws PHP warning when $menu is null
-----------------------------------------+------------------------------
Reporter: anonymized_15266067 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: normal | Resolution:
Keywords: has-patch reporter-feedback | Focuses: administration
-----------------------------------------+------------------------------
Comment (by njwp):
same issue with me. I suspect it is if woocommerce is installed.
I use admin_init
As far as I can see admn_init seems to be run twice - once when the menu
exists and once when it doesn't. So the menu items are actually correctly
removed (in the instance when the menu has a value) but the error is
thrown in the instance when the menu doesn't have a value. I could be
totally wrong but that's what it feels like.
Instead of using remove_menu_page, I just used the code from that
function in my functions.php and wrapped it with
if($menu){}
Works perfectly.
Compare to the remove_submenu_page function which DOES check for existence
of the menu item:
if ( ! isset( $submenu[ $menu_slug ] ) ) {
return false;
}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61962#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list