最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - What's causing this error? "Warning: Invalid argument"

matteradmin9PV0评论

I noticed today that my error logs are littered with this information. I'm not quite sure what's causing it. Has anyone seen this before?

[Mon Mar 25 17:24:23 2013] [error] [client] PHP Warning: Invalid argument supplied for foreach() in /var/www/html/mysite/wp-admin/includes/plugin.php on line 1290, referer: http://mysite/contact/

Line 1290 is the foreach in the following code. I am not sure what's referencing this or where to begin looking.

/**
 * Remove a top level admin menu
 *
 * @since 3.1.0
 *
 * @param string $menu_slug The slug of the menu
 * @return array|bool The removed menu on success, False if not found
 */

function remove_menu_page( $menu_slug ) {
global $menu;

foreach ( $menu as $i => $item ) {
    if ( $menu_slug == $item[2] ) {
        unset( $menu[$i] );
        return $item;
    }
}

return false;
}

I'm not hooking into admin_menu as far as I can tell.

Any ideas?

I noticed today that my error logs are littered with this information. I'm not quite sure what's causing it. Has anyone seen this before?

[Mon Mar 25 17:24:23 2013] [error] [client] PHP Warning: Invalid argument supplied for foreach() in /var/www/html/mysite/wp-admin/includes/plugin.php on line 1290, referer: http://mysite/contact/

Line 1290 is the foreach in the following code. I am not sure what's referencing this or where to begin looking.

/**
 * Remove a top level admin menu
 *
 * @since 3.1.0
 *
 * @param string $menu_slug The slug of the menu
 * @return array|bool The removed menu on success, False if not found
 */

function remove_menu_page( $menu_slug ) {
global $menu;

foreach ( $menu as $i => $item ) {
    if ( $menu_slug == $item[2] ) {
        unset( $menu[$i] );
        return $item;
    }
}

return false;
}

I'm not hooking into admin_menu as far as I can tell.

Any ideas?

Share Improve this question asked Mar 25, 2013 at 21:32 PatPat 6812 gold badges10 silver badges29 bronze badges 4
  • 1 This is most likely caused by a plugin. Deactivate them all, and reactivate one by one. – vancoder Commented Mar 25, 2013 at 21:34
  • Looks like I narrowed it down to a plugin, which tells me I must have been getting this error for a few months and just didn't notice. Pop that one liner into an answer and I'll check it off for you. Thanks @vancoder – Pat Commented Mar 25, 2013 at 22:04
  • Was it a Twitter (or twitter related) plugin perchance? they've recently updated their API so a lot of plugins are failing. – vancoder Commented Mar 25, 2013 at 22:15
  • No it was WP Most Popular (which for what it's worth, never seemed to work rock-solid anyways). wordpress/extend/plugins/wp-most-popular – Pat Commented Mar 25, 2013 at 22:16
Add a comment  | 

2 Answers 2

Reset to default 2

This is most likely caused by a plugin. Deactivate them all, and reactivate one by one.

I had same problem while developing my own plugin. Turns out that I didn't uninstall menu the right way in uninstall.php. Here is right way with hook:

function myplugin_remove_menus() {
remove_menu_page( 'myplugin-admin-menu' );
remove_menu_page( 'myplugin-admin-menu-logs' );
}
// proper way with admin_menu hook
add_action( 'admin_menu', 'myplugin_remove_menus' );
Post a comment

comment list (0)

  1. No comments so far