As designed Custom user field deletion does not delete entry data

rugk

Active member
#1
When you delete a custom user field the data set by users for this field is not deleted from the database and can still be used by add-ons e.g.
I doubt this is intended.
 

Chris D

XenForo developer
Staff member
#2
There's code to remove the values via the _postDelete method of the DataWriter:
PHP:
$this->_db->delete('xf_user_field_value', 'field_id = ' . $this->_db->quote($fieldId));
// note the user caches aren't rebuilt here; this shouldn't be an issue as we don't enumerate them
Unless you're talking about the cache of the field values in the xf_user_profile template, in which case this is expected (as suggested by the comment above).
 

rugk

Active member
#3
In my test it is just did not got deleted. I don't know whether this is caused by a cache.
But after the user changes one of the other user fields after the deletion of the one field, the previously deleted field is also (correctly) deleted from $user['customFields'].
 

Mike

XenForo developer
Staff member
#4
This is expected an mentioned in the comment Chris quoted. You can rebuild user info if you really want to get rid of it, but there isn't an expectation that a field would be accessed that doesn't exist (and we never loop through the custom field cache for display).
 

rugk

Active member
#5
Okay, but if I have an add-on which uses this 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.

Feel free to move this post into the Dev-Support/Help section if you want to.
 
Top