Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove_menu_page(): E_WARNING: Invalid argument supplied for foreach() #21

Closed
dac514 opened this issue Apr 6, 2018 · 2 comments
Closed

Comments

@dac514
Copy link

dac514 commented Apr 6, 2018

remove_menu_page() sometimes : 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?

Upstream bug report:
https://core.trac.wordpress.org/ticket/43714

@darrenjacoby
Copy link
Owner

Seems like a WP issue, so closing for now.

@losderpos
Copy link

Fixed doing this:

if (function_exists('\Sober\Intervention\intervention') && !(defined('DOING_AJAX') && DOING_AJAX)) {
    intervention('remove-menu-items', 'posts', 'all');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants