Warning: Invalid argument supplied for foreach() in wp-all-import-pluggable.php

Hello, I’m getting the following error back from my wordpress cron history logs:

Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce-role-based-price-master/plugins/wp-all-import-integration/wp-all-import-pluggable.php on line 49

Below is the code in question, but I’m new to PHP and can’t quite see whats gone wrong, can anyone spot anything immediately wrong with the for each loop set up on line 49?

[php]function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = “”) {

		$field =  array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug);

		$this->fields[$field_slug] = $field;

		if ( ! empty($enum_values) ){
			foreach ($enum_values as $key => $value) {
				if (is_array($value))
				{
					if ($field['type'] == 'accordion')
					{
						$this->fields[$value['slug']]['is_sub_field'] = true;
					}
					else
					{
						foreach ($value as $n => $param) {
							if (is_array($param) and ! empty($this->fields[$param['slug']])){
								$this->fields[$param['slug']]['is_sub_field'] = true;
							}
						}
					}
				}
			}
		}

		return $field;

	}

	/**
	*
	* Add an option to WP All Import options list
	*
	* @param string $slug - option name
	* @param string $default_value - default option value
	*
	*/
	function add_option($slug, $default_value = ''){
		$this->options[$slug] = $default_value;
	}

	function options_array() {

		$options_list = array();

		foreach ($this->fields as $field_slug => $field_params) {
			if (in_array($field_params['type'], array('title', 'plain_text'))) continue;
			$default_value = '';
			if (!empty($field_params['enum_values'])){
				foreach ($field_params['enum_values'] as $key => $value) {
					$default_value = $key;
					break;
				}
			}
			$options_list[$field_slug] = $default_value;
		}

[/php]

The problem is, you are checking to see if $enum_values is not empty, not if it is an array.

Sponsor our Newsletter | Privacy Policy | Terms of Service