1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to make an add-on to add a custom user field?

Discussion in 'XenForo Development Discussions' started by Dadparvar, Apr 15, 2016.

  1. Dadparvar

    Dadparvar Well-Known Member


    I created an add-on. But it need a custom user field to be added in each site that add-on is going to be installed.

    How can I do it? I don't see any option to associated a custom field to any add-on.

  2. Steve F

    Steve F Well-Known Member

    Custom User Fields can't be associated with an add-on, sadly. Though you can create, modify and delete them through your add-on using the DataWriter.

    Here is a short example from my Gamer Profiles add-on.
        public static function install($existingAddOn)
            if (
    XenForo_Application::$versionId 1040800)
    // note: this can't be phrased
    throw new XenForo_Exception('This add-on requires XenForo 1.4.3 or higher.'true);
    // Checks if add-on is already present if it is skip creating the Custom User Field
    if (!$existingAddOn)

    $dw XenForo_DataWriter::create('XenForo_DataWriter_UserField');
    $dw->setExtraData(XenForo_DataWriter_UserField::DATA_DESCRIPTION'Enter your Twitch user name here to link to your channel page');
    // Deletes Custom User Field when add-on is uninstalled
    public static function uninstall()
    $dw XenForo_DataWriter::create('XenForo_DataWriter_UserField');
    Dadparvar likes this.
  3. Dadparvar

    Dadparvar Well-Known Member


    Helped a lot.

    It seems this codes doesn't add user field while upgrading add-on? (if in previous installed version still those fields are not created yet). Right? Any idea?
  4. Xon

    Xon Well-Known Member

        public static function install($existingAddOn)
            $version = isset($existingAddOn['version_id']) ? $existingAddOn['version_id'] : 0;
            if ($version < 10000)
    Where $version is being compared to the add-on's version_id attribute.
    Dadparvar and Steve F like this.

Share This Page