Support » Plugin: Remove admin menus by roles » remove_menu_page(): E_WARNING: Invalid argument supplied for foreach()

  • Resolved unostar

    (@unostar)


    Hey,

    While tracking the source of warnings constantly filling debug log found out it was due to the following line in this plugin:

    remove-admin-menus-by-role.php:169:

    foreach($menus_hidden as $menu)
      remove_menu_page($menu);

    If you check remove_menu_page() reference, it says:

    This function should be called on the admin_menu action hook. Calling it elsewhere might cause issues: either the function is not defined or the global $menu variable used but this function is not yet declared.

    The correct code should be:

    foreach($menus_hidden as $menu)
      add_action('admin_menu', remove_menu_page($menu));

    Please consider.

    Thanks

    • This topic was modified 2 months, 2 weeks ago by unostar.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.