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

bottiger

Active member
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();
 
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;
                        }
                    }
                }
 
Top Bottom