www.webdeveloper.com
Results 1 to 9 of 9

Thread: Please Help! Invalid Argument issue

  1. #1
    Join Date
    Nov 2012
    Posts
    5

    Please Help! Invalid Argument issue

    hi friends i use wordpress but when in active yoo theme its show error but i don't know about this error please help

    error show
    Code:
    Warning:  Invalid argument supplied for foreach() in /public_html/wp-content/themes/yoo_catalyst/warp/systems/wordpress.3.0/helpers/widgets.php on line 107
    code

    PHP Code:
     <?php
    /**
    * @package   Warp Theme Framework
    * @author    YOOtheme http://www.yootheme.com
    * @copyright Copyright (C) YOOtheme GmbH
    * @license   YOOtheme Proprietary Use License (http://www.yootheme.com/license)
    */

    /*
        Class: WidgetsWarpHelper
            Wordpress widget helper class, provides simplyfied access to wordpress widgets
    */
    class WidgetsWarpHelper extends WarpHelper {

        
    /* widgets */
        
    public $widgets;
        
        
    /* options */
        
    public $options;

        
    /*
            Function: Constructor
                Class Constructor.
        */
        
    public function __construct() {
            
    parent::__construct();

            
    // set options
            
    $this->options get_option('warp_widget_options', array());
        }

        
    /*
            Function: get
                Retrieve a widget by id

            Parameters:
                $id - Widget ID

            Returns:
                Object
        */
        
    public function get($id) {
            global 
    $wp_registered_widgets;
            
            
    $widget null;

            if (isset(
    $wp_registered_widgets[$id]) && ($data $wp_registered_widgets[$id])) {
                
    $widget = new stdClass();
                
                foreach (array(
    'id''name''classname''description') as $var) {
                    
    $widget->$var = isset($data[$var]) ? $data[$var] : null;
                }

                if (isset(
    $data['callback']) && is_array($data['callback']) && ($object current($data['callback']))) {
                    if (
    is_a($object'WP_Widget')) {

                        
    $widget->type $object->id_base;

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

                            
    $number $data['params'][0]['number'];
                            
    $params get_option($object->option_name);

                            if (
    false === $params && isset($object->alt_option_name)) {
                                
    $params get_option($object->alt_option_name);
                            }

                            if (isset(
    $params[$number])) {
                                
    $widget->params $params[$number];
                            }
                        }
                    }
                } else if (
    $id == 'nav_menu-0') {
                    
    $widget->type 'nav_menu';
                }
                
                if (empty(
    $widget->name)) {
                    
    $widget->name ucfirst($widget->type);
                }

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

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

        
    /*
            Function: getWidgets
                Retrieve widgets

            Parameters:
                $position - Position

            Returns:
                Array
        */
        
    public 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->get($id);
                    }
                }
            }

            if (!
    is_null($position)) {
                return isset(
    $this->widgets[$position]) ? $this->widgets[$position] : array();
            }
            
            return 
    $this->widgets;
        }

        
    /*
            Function: _display
                Checks if a widget should be displayed

            Returns:
                Boolean
        */
        
    protected function _display($widget) {
            if (!isset(
    $widget->options['display']) || in_array('*'$widget->options['display'])) return true;
            
            
    $query $this['system']->getQuery();

            foreach (
    $query as $q) {
                  
               if (
    in_array($q$widget->options['display'])) {
                    
                    switch(
    $q) {
                        case 
    "page":
                            
                            if(
    is_home()) {
                                return 
    in_array('home'$widget->options['display']);
                            }

                            if(
    is_front_page()) {
                                return 
    in_array('front_page'$widget->options['display']);
                            }

                        default:
                            return 
    true;
                    }
                }
            }

            return 
    false;
        }

    }

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    It's telling you that on that line, $ids is not an array. As to why not, that would take some debugging to find out the call to wp_get_sidebars_widgets() is actually returning -- my guess is that it's returning Boolean false. You could try to debug with something like:
    PHP Code:
        public function getWidgets($position null) {

            if (empty(
    $this->widgets)) {
                
    $sideBarWidgets wp_get_sidebar_widgets();
                foreach (
    $sideBarWidgets as $pos => $ids) {
                    if( ! 
    is_array($ids)) {
                        die(
    "<pre>Not an array:\n".var_export($sideBarWidgetstrue)."</pre>");
                    }
                    
    $this->widgets[$pos] = array();
                    foreach (
    $ids as $id) {
                        
    $this->widgets[$pos][$id] = $this->get($id);
                    }
                }
            } 
    Or you could try contacting the theme creator, or see if there is a new version of the theme.
    "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

  3. #3
    Join Date
    Nov 2012
    Posts
    5
    thanks for reply sir but now this error show
    Code:
    Fatal error: Call to undefined function wp_get_sidebar_widgets() in /home/semdr786/public_html/wp-content/themes/yoo_catalyst/warp/systems/wordpress.3.0/helpers/widgets.php on line 105

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    That's because I made a typo, and "sidebars" should be plural.
    "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

  5. #5
    Join Date
    Nov 2012
    Posts
    5
    what do?

  6. #6
    Join Date
    Nov 2012
    Posts
    5
    please help me

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Code:
    $sideBarWidgets = wp_get_sidebars_widgets();
    "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

  8. #8
    Join Date
    Nov 2012
    Posts
    5
    now show this
    Not an array:
    array (
    'wp_inactive_widgets' =>
    array (
    0 => 'meta-2',
    1 => 'categories-2',
    2 => 'search-4',
    3 => 'search-3',
    ),
    'general' =>
    array (
    0 => 'search-2',
    1 => 'text-2',
    2 => 'recent-posts-2',
    3 => 'recent-comments-2',
    4 => 'pages-2',
    5 => 'archives-2',
    6 => 'text-3',
    ),
    'slider' =>
    array (
    ),
    'homepage' =>
    array (
    ),
    'post' =>
    array (
    ),
    'page' =>
    array (
    ),
    'blog' =>
    array (
    ),
    'contact' => NULL,
    'portfolio' => NULL,
    'other' =>
    array (
    ),
    'footer-1' => NULL,
    'footer-2' => NULL,
    'footer-3' => NULL,
    )

  9. #9
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    So, it looks like some elements are arrays and some are simple scalars with NULL values. I'm hesitant to suggest a final solution, since I don't really know what all this is supposed to do, nor how critical it is, but the simple solution to avoid the error might be something like:
    PHP Code:
        public function getWidgets($position null) {

            if (empty(
    $this->widgets)) {
                
    $sideBarWidgets wp_get_sidebar_widgets();
                foreach (
    $sideBarWidgets as $pos => $ids) {
                    if( ! 
    is_array($ids)) {
                        continue; 
    // just skip this item
                    
    }
                    
    $this->widgets[$pos] = array();
                    foreach (
    $ids as $id) {
                        
    $this->widgets[$pos][$id] = $this->get($id);
                    }
                }
            } 
    "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

Thread Information

Users Browsing this Thread

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

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