www.webdeveloper.com
Results 1 to 10 of 10

Thread: [RESOLVED] Please Help! Invalid Argument issue

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    14

    resolved [RESOLVED] Please Help! Invalid Argument issue

    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

    Link to page: http://mxvsatv.derekfoulk.com/


    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;
    }
    }

    return false;
    }

  2. #2
    Join Date
    Feb 2012
    Posts
    14
    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!

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,633
    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

    eBookworm.us

  4. #4
    Join Date
    Jul 2009
    Location
    My house, sitting at the computer. Duh!
    Posts
    118
    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;
    }
    }

    return 
    false;


  5. #5
    Join Date
    Feb 2012
    Posts
    14
    I'll give it a shot thanks for the reply

  6. #6
    Join Date
    Feb 2012
    Posts
    2

    Cool my wordpress problam

    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

  7. #7
    Join Date
    Feb 2012
    Posts
    2
    Quote Originally Posted by manammanam View Post
    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

    : null;
    }

    if (isset($data['callback']) && ($object = current($data['callback']))) {
    if (is_a($object, 'WP_Widget')) {
    $widget->type = $object->id_base;
    }
    } elseif($id=='nav_menu-0') {
    $widget->type = 'nav_menu';
    }

    if (isset($data['params'][0]['number'])) {

    $number = $data['params'][0]['number'];
    $params = get_option($widget->classname);

    if (isset($params[$number])) {
    $widget->params = $params[$number];
    }
    }

    if (empty($widget->name)) {
    $widget->name = ucfirst($widget->type);
    }

    if (empty($widget->params)) {
    $widget->params = array();
    }

    $widget->options = isset($options[$id]) ? $options[$id] : array();
    $widget->display = $this->displayWidget($widget);
    }

    return $widget;
    }

    /*
    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;
    }

  8. #8
    Join Date
    Feb 2012
    Posts
    14

    Cool

    Thanks guys. Got it running. Amazing what you can do when you learn PHP. Took about two days to get a decent understanding. I've been missing out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles