Data passed to custom userfield callbacks

Jake Hakoda Shirley

Active member
Hey guys, I am currently trying to make it so our users cannot enter the same in-game name as another user on the forum. To my knowledge, the custom userfield callback method only supports three variables, those being 'array $field, &$value, &$error'. Is there any way I could grab the user's info (who is submitting the name)?
 
This PHP code will give you access to the user record of the currently logged in user:

Code:
		$visitor = XenForo_Visitor::getInstance();
		if ($visitor['user_id'] == ...)
		{
			...
		}
 
BUT attention:
Admins (with user edit permissions) can edit everybody in the acp.

So if they edit a userfield, $visitor won't be the user with the field, it will be the admin who's changing the value;)
 
BUT attention:
Admins (with user edit permissions) can edit everybody in the acp.

So if they edit a userfield, $visitor won't be the user with the field, it will be the admin who's changing the value;)

Interesting, I wasn't aware the custom field callbacks execute in the admin CP. Anyway, for handling verification / extra processing on our custom fields I extended the actionPersonalDetailsSave function, and that doesn't get executed on the admin CP.
 
the custom field callback is a validator which is run everywhere where the custom fields are set via the user datawriter

XenForo_DataWriter_User::setCustomFields
PHP:
....
$valid = $fieldModel->verifyUserFieldValue($field, $value, $error);
if (!$valid)
{
$this->error($error, "custom_field_$fieldId");
continue;
}
 
if (!$this->getOption(self::OPTION_ADMIN_EDIT) && $field['required'] && ($value === '' || $value === array()))
{
$this->error(new XenForo_Phrase('please_enter_value_for_all_required_fields'), "custom_field_$fieldId");
continue;
}
 
Top Bottom