Check whether custom user field (really) exists? (no cache)

rugk

Active member
(moved from a bug report)

If I have an add-on which uses a custom user field, how can I check whether the field exists?
array_key_exist does not really help, because it only checks the cache in this case.

Without this check the field is still considered valid even when the field was in fact deleted by the admin.
 

Jeremy P

Well-known member
Not sure if you still need it, but you can check if a field is actually defined using something like:
PHP:
$visitor = \XF::visitor();
$fieldSet = $visitor->Profile->custom_fields;
$definitionSet = $fieldSet->getDefinitionSet();

if (isset($definitionSet->field_id)) {
    ...
}
 
Top