Opened 2 months ago

Last modified 2 months ago

#23767 new enhancement

remove_menu_page: Check for existing menu items

Reported by: sergej.mueller Owned by:
Priority: normal Milestone: Awaiting Review
Component: Warnings/Notices Version: 3.5
Severity: normal Keywords: has-patch close
Cc:

Description

This error appears in my error log:

PHP Warning: Invalid argument supplied for foreach() in /www/htdocs/wp-admin/includes/plugin.php on line 1290

The if-empty patch is attached.

Attachments (1)

plugin.php.patch (375 bytes) - added by sergej.mueller 2 months ago.

Download all attachments as: .zip

Change History (4)

  • Keywords close added
  • Type changed from feature request to enhancement
  • Version changed from trunk to 3.5

Looks like there are only two ways to get this warning:

  1. Call remove_menu_page() after the admin is fully loaded, but before $menu global is set up, e.g. by hooking into auth_redirect action instead of admin_menu, which goes against the Codex example: http://codex.wordpress.org/Function_Reference/remove_menu_page.
  2. Manually unset the $menu global at some point.

Both are developer errors, so the developer should see the warning.

Any foreach command should be checked "if empty".

Similar enhancements were suggested in #17299 and #18927.

The consensus was that we shouldn't hide warnings generated by plugin or theme bugs. That would only make debugging harder.

Note: See TracTickets for help on using tickets.