Add/Remove custom profile fields upon installation/uninstallation?

Z61

Well-known member
Is it possible to add or remove custom profile fields upon installation? If it is, can someone please lead me in the correct direction? I can't seem to figure it out and searching didn't provide what I am looking for.
 
Would you mind showing a snippet?

Code:
$writerData = array(
    'field_id'            => 'unique_id_for_field', // Unique Identifier for the field - probably best to prefix it with your add-on ID
    'display_group'        => 'preferences', // Group to display in: personal, contact, preferences
    'display_order'        => 10, // The position (relative to other fields in the group) to display this field at
    'field_type'        => 'textbox', // Type of field (textbox, textarea, select, radio, checkbox, multiselect)
    'show_registration'    => 0, // Whether to show on registration.
    'required'            => 1, // Whether the field is required.
    'user_editable'        => 1, // Whether the user can edit the field
    'viewable_profile'    => 1, // Show on profile
    'viewable_message'    => 1, // Show in postbit
);
$writer = XenForo_DataWriter::create('XenForo_DataWriter_UserField');
$writer->bulkSet($writerData);
$writer->save();

There are a few other fields you can use, reference XenForo_DataWriter_UserField for those :)
 
  • Like
Reactions: Z61
It's probably better to use the DataWriter during install.

See the installer of this add-on for an example:
https://xenforo.com/community/resources/display-e-mail-address-in-profile.810/

The code is ancient, and could be a bit slicker, but the basic premise is there.
Code:
$writerData = array(
    'field_id'            => 'unique_id_for_field', // Unique Identifier for the field - probably best to prefix it with your add-on ID
    'display_group'        => 'preferences', // Group to display in: personal, contact, preferences
    'display_order'        => 10, // The position (relative to other fields in the group) to display this field at
    'field_type'        => 'textbox', // Type of field (textbox, textarea, select, radio, checkbox, multiselect)
    'show_registration'    => 0, // Whether to show on registration.
    'required'            => 1, // Whether the field is required.
    'user_editable'        => 1, // Whether the user can edit the field
    'viewable_profile'    => 1, // Show on profile
    'viewable_message'    => 1, // Show in postbit
);
$writer = XenForo_DataWriter::create('XenForo_DataWriter_UserField');
$writer->bulkSet($writerData);
$writer->save();

There are a few other fields you can use, reference XenForo_DataWriter_UserField for those :)
Thank you both. This is exactly what I needed :).
 
Back
Top Bottom