1. 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?

Discussion in 'XenForo Development Discussions' started by bottiger, Nov 27, 2011.

  1. bottiger

    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();
     
  2. Fuhrmann

    Fuhrmann Well-Known Member

    Use this before you call to the setCustomFields:

    PHP:
    $writer->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDITtrue);
    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;
                            }
                        }
                    }
     
    Sim, W1zzard and bottiger like this.

Share This Page