The error line comes from the following in wp-admin/includes/plugin.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;
}
The global $menu
does not actually get populated until the wp-admin/menu-header.php
is included. See admin.php
-> admin-header.php
as well. Any hook prior to that include is going to throw a similar error.
The admin_init
hook is too early to access the global $menu
. You should be using the admin_menu
hook instead.