#43714 closed defect (bug) (duplicate)
remove_menu_page(): E_WARNING: Invalid argument supplied for foreach()
| Reported by: | conner_bw | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 4.9.5 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
remove_menu_page() sometimes logs: E_WARNING: Invalid argument supplied for foreach()
Problematic code:
function remove_menu_page( $menu_slug ) {
global $menu;
foreach ( $menu as $i => $item ) {
// ...
URL /wp/wp-admin/admin-ajax.php
HTTP referrer https://_SOME_SITE_/wp/wp-admin/network/users.php
Stack trace
/vendor/soberwp/intervention/src/Module/RemoveMenuItems.php (121) /web/wp/wp-includes/class-wp-hook.php (286) /web/wp/wp-includes/class-wp-hook.php (310) /web/wp/wp-includes/plugin.php (453) /web/wp/wp-admin/admin-ajax.php (44)
Offending line:
https://github.com/soberwp/intervention/blob/7d69c58b32fce29aad08e4ff9c9de43963122610/src/Module/RemoveMenuItems.php#L121
Possible reason: global $menu not defined?
Change History (5)
#2
@
8 years ago
I could not reproduce without third-party code.
I fixed it by changing:
require get_template_directory() . '/inc/intervention.php';
To:
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
require get_template_directory() . '/inc/intervention.php';
}
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
@conner_bw thanks for the ticket! It looks like you're calling
remove_menu_item()via a custom framework. Are you able to reproduce this error with a clean install of WordPress without any third-party code?