public static function installer($existingAddOn)
{
if (!$existingAddOn)
{
$dw = XenForo_DataWriter::create('XenForo_DataWriter_UserField');
$dw->set('field_id', 'displayEmailAddress');
$dw->set('display_group', 'preferences');
$dw->set('display_order', 1);
$dw->set('field_type', 'select');
$dw->set('required', 1);
$dw->set('show_registration', 1);
$dw->set('user_editable', 'yes');
$dw->set('viewable_profile', '0');
$choices = array(
'hide' => 'Hide',
'show' => 'Show'
);
$dw->setFieldChoices($choices);
$dw->save();
}
}
public static function installer($existingAddOn)
{
if (!$existingAddOn)
{
$dw = XenForo_DataWriter::create('XenForo_DataWriter_UserField');
$dw->set('field_id', 'URL_myaddon');
$dw->set('display_group', 'preferences');
$dw->set('display_order', 1);
$dw->set('field_type', '[B]textbox[/B]');
$dw->set('required', 1);
$dw->set('show_registration', 1);
$dw->set('user_editable', 'yes');
$dw->set('viewable_profile', '0');
$dw->save();
}
}
This might seems stupid as my experience with Xenforo adgon creation is really limited!That's what the code above does
<?php
class WGBB_tpoh_installer
{
public static function tpoh_installr()
{
$dw = XenForo_DataWriter::create('XenForo_DataWriter_UserField');
$dw->set('field_id', 'URL"');
$dw->set('display_group', 'personal');
$dw->set('display_order', 10);
$dw->set('field_type', 'textbox');
$dw->set('required', 1);
$dw->set('show_registration', 1);
$dw->set('user_editable', 'yes');
$dw->set('viewable_profile', '0');
$dw->save();
}
}
?>
It just uses the existing DataWriter.
Are you getting an error? The above should work.
Disabling and enabling the addon will do or do I have to delete the addon and reinstall it again?You will need to install or upgrade the add-on first. Have you done that?
public static function uninstaller()
{
$db = XenForo_Application::get('db');
$db->query("DELETE FROM `xf_user_field` WHERE `xf_user_field`.`field_id` = 'displayEmailAddress'");
$db->query("DELETE FROM `xf_user_field_value` WHERE `xf_user_field_value`.`field_id` = 'displayEmailAddress'");
}
If you're releasing an add-on that requires a custom user profile field, you will need to run a couple of database queries during the install of the add-on.
Here's an example function from one of my add-ons:
PHP:public static function installer($existingAddOn) { if (!$existingAddOn) { $dw = XenForo_DataWriter::create('XenForo_DataWriter_UserField'); $dw->set('field_id', 'displayEmailAddress'); $dw->set('display_group', 'preferences'); $dw->set('display_order', 1); $dw->set('field_type', 'select'); $dw->set('required', 1); $dw->set('show_registration', 1); $dw->set('user_editable', 'yes'); $dw->set('viewable_profile', '0'); $choices = array( 'hide' => 'Hide', 'show' => 'Show' ); $dw->setFieldChoices($choices); $dw->save(); } }
Hopefully most of the options above should be self explanatory in relation to the options you get in the Admin CP.
Also, you may not need field choices if you're just doing a text box.
Set an uninstall method
This is an example from one of my add-ons again:
PHP:public static function uninstaller() { $db = XenForo_Application::get('db'); $db->query("DELETE FROM `xf_user_field` WHERE `xf_user_field`.`field_id` = 'displayEmailAddress'"); $db->query("DELETE FROM `xf_user_field_value` WHERE `xf_user_field_value`.`field_id` = 'displayEmailAddress'"); }
$dw = XenForo_DataWriter::create('XenForo_DataWriter_UserField');
$dw->setExistingData('steamUserProfile');
$dw->delete();
Yeah that's a bad way to do it.Set an uninstall method
This is an example from one of my add-ons again:
PHP:public static function uninstaller() { $db = XenForo_Application::get('db'); $db->query("DELETE FROM `xf_user_field` WHERE `xf_user_field`.`field_id` = 'displayEmailAddress'"); $db->query("DELETE FROM `xf_user_field_value` WHERE `xf_user_field_value`.`field_id` = 'displayEmailAddress'"); }
We use essential cookies to make this site work, and optional cookies to enhance your experience.