MyBB Community Forums

Full Version: Invalid argument supplied for each ()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I got this error message when registering as a member. The MyBB version is 1.6.9

I believe it's related to the Socialsites plugin, but I don't know how to fix this. Help, please?

Message:
Quote:Warning [2] Invalid argument supplied for foreach() - Line: 642 - File: inc/plugins/socialsites.php PHP 5.3.19 (Linux)
File Line Function
/inc/plugins/socialsites.php 642 errorHandler->error
/inc/plugins/socialsites.php 516 socialsites_update_user_sites
/inc/class_plugins.php 101 socialsites_do_register
/member.php 299 pluginSystem->run_hooks

And the content of the 'socialsites.php', around the mentioned lines:

516   	socialsites_update_user_sites($mybb->input['socialsites'], $user_info['uid']);

629   function socialsites_update_user_sites($sites, $uid)
630  {
631	global $db, $cache;
632	
633	$uid = intval($uid);
634	
635	$query = $db->simple_select("socialsites", "*", "", array("order_by" => "nicename", "order_dir" => "ASC"));
636	$social_sites = array();
637	while($socialsite = $db->fetch_array($query))
638	{
639		$social_sites[$socialsite['nicename']] = $socialsite;
640	}
641	$socialsites = array();
642	foreach($sites as $site => $id)
643	{
644		if(!array_key_exists($site, $social_sites) || empty($id))
645		{
646			continue;
647		}
648		$socialsites[$site] = $id;
649	}
650	
651	ksort($socialsites);
652	$socialsites = serialize($socialsites);
653	
654	$update = array(
655		"socialsites" => $db->escape_string($socialsites)
656	);

Class_plugins:

81	function run_hooks($hook, &$arguments="")
82	{
83		if(!is_array($this->hooks[$hook]))
84		{
85			return $arguments;
86		}
87		$this->current_hook = $hook;
88		ksort($this->hooks[$hook]);
89		foreach($this->hooks[$hook] as $priority => $hooks)
90		{
91			if(is_array($hooks))
92			{
93				foreach($hooks as $hook)
94				{
95					if($hook['file'])
96					{
97						require_once $hook['file'];
98					}
99					
100					$func = $hook['function'];
101					$returnargs = $func($arguments);
102					
103					
104					if($returnargs)
105					{
106						$arguments = $returnargs;
107					}
108				}
109			}
110		}
111		$this->current_hook = '';
112		return $arguments;
113	}

and finally, the member.php:
299			$plugins->run_hooks("member_do_register_end");

Your help is appreciated, thank you!!! Big Grin
The member.php hook is to do with the function that socialsites is adding to that place in the member.php file. All in all you can blame socialsites for this error. I'm not to sure about how to fix it but it seems the socialsites_do_register function has an error in it or is conflicting with another plugin.
./inc/plugins/socialsites.php, line 633:

$uid = intval($uid);

Before this, add:

if(!$sites)
{
	$sites = array();
}
worked like a charm!... Big Grin

Thank you and HAPPY HOLIDAYS!!!