Can I undelete a custom user field?

I accidentally deleted a custom user field. Does that mean that it is entirely deleted from the database or is it still there?

If it is still there, is there any way of undeleting it (apart from restoring a backup)? Or to access the contents via the data explorer?

I’m 95% sure a deleted custom field is gone forever.

If you can’t see it in data explorer, it’s not there anymore.

3 Likes

Just a thought, but surely there would be a way to recreate the Custom Field and hack together a script to retrieve and refill the data from within a backup using a temporary cloud server to write out the data from the original Custom Field?

Thanks for your thoughts. Yes, that’s obviously what backups are for. I don’t know what the smartest procedure would be for restoring user field content for, say, thousands of users. For me, the number the easiest procedure was to just do it manually. And that was actually surprisingly easy, so I mention it here (from memory, so I may have missed some detail):

  • When you download the backup file and open it for example with good old WinRAR, you’ll find another archive in there, so open that with WinRAR too. You’ll find an .sql file.
  • And now comes the good part: you can just open it as a text file (with the built-in WinRAR viewer or otherwise).
  • Search for the name of the field or some content you hapoen to know and you’ll find the table for that user field.
  • Now the only trickyness is that (at least in my case) the user ID is not the first but the second value in each row (I’d be curious what the first value represents (“COPY”)).
2 Likes

Currently, deleting a custom field (tables user_fields and user_fields_options if its field_type is dropdown) doesn’t delete the actual values for the users (table user_custom_fields), so a quick (but potentially dangerous: backup first) workaround is to:

  1. Manually create a new custom field
  2. Replace the new id user_fields with the old one (this requires admin access to the database): UPDATE user_fields SET id=1 WHERE id=3; (assuming 3 is the new id and 1 is the old one)
  3. If the field was a dropdown, you’d have to do a similar thing in user_field_options
  4. If any users signed up for your site and filled out the new field before you fixed it (or if any existing user filled out the new field), you’d also have to fix those.
2 Likes