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

How to edit custom profile field that is not user editable?

bottiger

Active member
#1
How do I edit a custom profile field that is not user editable?

The following code allows me to set the field only if I make the field editable by any users. I do not want to let people edit this field because it allows them to impersonate other people.

PHP:
            $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
            $writer->setExistingData($visitorId);
            $writer->setCustomFields(array('Steam' => $id), array('Steam'));
            $writer->save();
 

Fuhrmann

Well-known member
#2
Use this before you call to the setCustomFields:

PHP:
$writer->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
Why use this?

In the function setCustomFields have this conditional:

PHP:
if (!$this->getOption(self::OPTION_ADMIN_EDIT))
                {
                    if ($field['user_editable'] == 'never')
                    {
                        continue;
                    }
                    else if ($field['user_editable'] == 'once')
                    {
                        if ($existingValue !== null && $existingValue !== '' && $existingValue !== array())
                        {
                            continue;
                        }
                    }
                }