• I’m using a nightly build from January 30th. I’ve made a plug-in that injects itself into the Admin Menu. It works but I get the following error:
    Warning: Invalid argument supplied for foreach() in /home/zsd/clients/cadex/httpdocs/wp-admin/admin-functions.php on line 874

    In my plugin file I add the submenus with this:
    add_submenu_page(__(“profile.php”), __(‘Clients’), __(‘Clients’), 8, ‘softshop_clients.php’);
    add_submenu_page(__(“profile.php”), __(‘Orders’), __(‘Orders’), 8, ‘softshop_orders.php’);
    add_submenu_page(__(“profile.php”), __(‘Products’), __(‘Products’), 8, ‘softshop_products.php’);
    add_submenu_page(__(“profile.php”), __(‘Product Formats’), __(‘Product Formats’), 8, ‘softshop_productformats.php’);

    here is the function that is having trouble. The foreach statement is where the error is coming from:
    function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file) {
    global $submenu;
    global $menu;

    $parent = plugin_basename($parent);
    $file = plugin_basename($file);

    if (! isset($submenu[$parent]) && $file != $parent) {
    foreach ($menu as $parent_menu) {
    if ($parent_menu[2] == $parent) {
    $submenu[$parent][] = $parent_menu;
    }
    }
    }

    $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title);
    }

    If things are showing up ok on the menu, what is causing the invalid argument in the foreach? Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter zephyrsky

    (@zephyrsky)

    After more fiddling around I realized there wasn’t a menu item in there before my addittion. So it said to add a menu item calling back on itself. I did, and it eliminated the foreach error:

    add_submenu_page(__(“profile.php”), __(‘Manage’), __(‘Manage’), 8, ‘profile.php’);

    But, one problem.. This menu item is still showing up even though the add_submenu_page function is making sure that the $file and $parent don’t match:

    if (! isset($submenu[$parent]) && $file != $parent) {

    Thread Starter zephyrsky

    (@zephyrsky)

    Well, I hacked the admin-header.hp file and solved the problem. Under Submenus I added the IF statement after the foreach at line 34:

    <?php
    foreach ($submenu[“$parent_file”] as $item) :
    if ($item[2] != $parent_file) {

    and of course closed the if statement at line 50:

    }
    endforeach;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Invalid Arguement in Foreach when calling add_submenu_page’ is closed to new replies.