MyBB Community Forums

Full Version: PHP help Urgent!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this code that checks if the URL entered is correct it works but the problem is it shows error and at the same time allows user filed to be updated I mean it doesn't stop update how to stop updating when error shows?

// Google Plus	
	function cpfbbcode_goo()
{
	global $mybb, $db;
	
	$uid = $mybb->user['uid'];
    $googleplus = 'plus.google.com';
	$ufid = $db->fetch_array($db->simple_select('userfields', 'fid7', 'ufid = '.$uid));

	if($ufid['fid7'])
	{
	if(!strpos($ufid['fid7'], $googleplus))
    {
        error('The "Google Plus URL" input field contains non Google Plus URL please correct that or leave it empty!');
    }
	}
}

P.S.
$plugins->add_hook("usercp_do_profile_end", "cpfbbcode_goo");


I need a hook to
datahandler_user_update
because the update happens before
usercp_do_profile_end 

Could you please help me to adapt this code to work with new hook?
Well, i was first replying your thread, but, this is ... useless.

You are actually using a wrong algo here.

The fields are updated & then you have hooked your plugin, which queries the database (Producing an extra useless query) & checks if the data entered (earlier, whihc is already fed to the db) is good or not.

Well, i think, you should try to go for a more better way, that is:

Hook to datahandler_user_update

And perform a check on Usefields,

if(is_array($user['user_fields']))
{
    if(!strpos($user['user_fields']['fid7'], 'plus.google.com'))
    {
        // Remove FID7 from array. So it wont be updated!
        unset($user['user_fields']['fid7']);
    }
}

Reply me if it works, for i have not tested this. But i think, it should work. Be sure to either use global $user, Globals var to access the global $user for it is not static.
Thanks very much buddy it works great.

Listen please check your PM I sent you my core edit tell me what do you think if you can make it better then great!