I'm attemping to correct an issue with our WordPress template. Here is the error it's spitting out at me... Line 334 is red in the code below. That's where I believe my issue is. I'm fairly new at the coding side, I've been a designer for quite some time however, so please be easy on me lol. Thanks in advance!
Using WordPress 3.3.1 / Theme up-to-date as well / "Warp" framework by YooTheme
Warning: Invalid argument supplied for foreach() in /xxxx/xxxx/xxxx/xxxx/wp-content/themes/yoo_corona_wp/warp/systems/wordpress.3.0/helpers/system.php on line 334
/*
Function: getWidgets
Retrieve widgets
Parameters:
$position - Position
Returns:
Array
*/
function getWidgets($position = null) {
if (empty($this->widgets)) {
foreach (wp_get_sidebars_widgets() as $pos => $ids) {
$this->widgets[$pos] = array();
foreach ($ids as $id) {
$this->widgets[$pos][$id] = $this->getWidget($id);
}
}
}
if (!is_null($position)) {
return isset($this->widgets[$position]) ? $this->widgets[$position] : array();
}
return $this->widgets;
}
/*
Function: displayWidget
Checks if a widget should be displayed
Returns:
Boolean
*/
function displayWidget($widget) {
if (!isset($widget->options['display']) || in_array('*', $widget->options['display'])) return true;
foreach ($this->getQuery() as $q) {
if (in_array($q, $widget->options['display'])) {
return true;
}
}
Actually link to site is kinda pointless, sorry... going to work with a different template just incase I get no replies. It would be great if anyone could help me out here though, the template I'm having the issue with is the one we want to run with!
For whatever help it might be, the error is telling you that $ids is not an array, which is what foreach() expects it to be. As to why it's not an array -- or if it even should be -- is unknowable with the current info.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
The easy fix here is to check to see if $ids is a an array before foreaching it. That should suppress this particular error, although this could be a "band-aid" fix, as may be part of a larger problem.
PHP Code:
/*
Function: getWidgets
Retrieve widgets
Parameters:
$position - Position
Returns:
Array
*/
function getWidgets($position = null) {
if (empty($this->widgets))
{
foreach (wp_get_sidebars_widgets() as $pos => $ids)
{
$this->widgets[$pos] = array();
if (!empty($ids) && is_array($ids))
{
foreach ($ids as $id)
$this->widgets[$pos][$id] = $this->getWidget($id);
}
}
}
if (!is_null($position)) {
return isset($this->widgets[$position]) ? $this->widgets[$position] : array();
}
return $this->widgets;
}
/*
Function: displayWidget
Checks if a widget should be displayed
Returns:
Boolean
*/
function displayWidget($widget) {
if (!isset($widget->options['display']) || in_array('*', $widget->options['display'])) return true;
foreach ($this->getQuery() as $q) {
if (in_array($q, $widget->options['display'])) {
return true;
}
}
Warning: current() [function.current]: Passed variable is not an array or object in /home/xxxxx/public_html/wp-content/themes/yoo_expo_wp/warp/systems/wordpress.3.0/helpers/system.php on line 224
Warning: Invalid argument supplied for foreach() in /home/xxxxxx/public_html/wp-content/themes/yoo_expo_wp/warp/systems/wordpress.3.0/helpers/system.php on line 272
Warning: current() [function.current]: Passed variable is not an array or object in /home/xxxxx/public_html/wp-content/themes/yoo_expo_wp/warp/systems/wordpress.3.0/helpers/system.php on line 224
Warning: Invalid argument supplied for foreach() in /home/xxxxxx/public_html/wp-content/themes/yoo_expo_wp/warp/systems/wordpress.3.0/helpers/system.php on line 272
Hi Guys i was also wondering how you fixed this problem. I have the same error for a yootheme.
Warning: Invalid argument supplied for foreach() in /home2/aussieba/public_html/dzonepattaya/wp-content/themes/yoo_shelf_wp/warp/systems/wordpress.3.0/helpers/widgets.php on line 107
I dont really understand why im getting this error. I used the same template on another website and it was fine. Ive checked the code on the other website using this theme and it looks exactly the same as it does when im trying to use it for the new website.
The only difference is the new website is using a newer instillation of wordpress but i dont think it should make any difference.
Anyhow, be good to here some suggestions, i see @gfogleman has been waiting for a while for his response to the same question so ill look for alternatives in the mean time.
Im not a programmer but can follow clear instructions.
Bookmarks