last day (15 days later) » 

23:25
1
A: How do I fix this error: Warning: invalid argument supplied for foreach()?

Chacha102This usually happens when you are trying to do admin navigation stuff and you aren't hooked into admin_menu. If you hook in before that, $menu hasn't been created yet. add_action('admin_menu', 'my_plugin_add_menu'); function my_plugin_add_menu(){ $ptype = 'my_post_type'; $ptype_obj = ge...

I tried removing all the admin nav stuff and the issue still remained. Here is a paste of the relevant functions.php code - do you see anything there? pastebin.com/2f1AaxPU
Are you using admin_init or admin_menu? There is a difference...
add_action( 'init', 'register_my_menus' );
I'm talking about for when you call 'remove_menu_page'
added the remove_menu_page code above
23:25
So, now you should go back and read my answer again, and see how it applies to the code you just gave me.
Ok - I edited the code and moved the add_action(...) above the function. I am still getting the error, however. Am I understanding you correctly?
No. you are using admin_init. When admin_init happens, the menus haven't been loaded. It isn't until admin_menu happens that $menu is loaded.
Hey
Anyone alive?
yeah
sorry it took me a while to get logged in - first time using the chat feature
ok sorry I'm new at some of this.. you might have to spell if out for me a little more.. I appreciate your help
23:29
No problem
So, hooks are like events in Wordpress
they happen in an order
got it
So, in this case, the code you posted was hooking into 'admin_init', which happens at the very beginning of an admin page load
you think my error is b/c mine are out of order somehow
ok
However, Wordpress's Codex tells us that we should use 'admin_menu', because that is when the menu is being renderred
Otherwise you'll try to remove an item that isn't even there yet
ok got it, so I'll go through and anytime I'm editing the admin menu I should use 'admin_menu' rather than 'admin_init'
23:32
Right
I ran into that problem a couple times with menus
ok I think I have that fixed, but I'm still getting the error
Really?
Same error?
it's interesting because I wasn't getting the error (and still am not) on my local build which has the same functions.php as the upload
yeah - it happens only on certain events
like in the appearance > widgets - adding a widget to a sidebar triggers the error in the sidebar
on settings > general -- changing the date structure and clicking away triggers the event
And it is when you reload right?
That sounds AJAXy..
nope - it's when I do something else - like update a meta box
or drag a widget into a sidebar
yeah - it feels ajaxy to me - it seems to trigger on ajax events
I feel like something got goofed up with my menus when I installed the clean version of wordpress and used the importer to bring in the info
but I don't have the first clue how to narrow it down
23:37
The first thing I'd do is find a cause. Comment out each add_action one at a time and test if the error still happens
When you find the offending function, then you can look at the hook it is hooked into, the parameters it is giving, etc
ok - believe it or not, I took my functions.php file down to the barebones twentyten functions and I'm still getting the error
Thats a problem :)
If possible, you might want to reinstall
Or try a different theme
yeah I'm going to reinstall and try again b/c something obviously got screwed up
with custom menus, when should I set up my menus
after I select my theme?
It shouldn't matter
But it can't hurt if you stick to after you select your theme
yeah, we'll see if it happens again. hopefully it's not related to godaddy -- it is weird that it's not happening at all on my local build
ok I'll do that and update the question afterward
thanks for your help
23:42
When you get into very complicated themes, it is best to select the theme, and THEN make customizations.
No problem. Its what I do for a living, kinda
yeah - I mean I've been building this custom theme for a while and testing - I'm at the deployment stage, and this bug came up. thanks again

last day (15 days later) »