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

Editing a user with custom field values

Discussion in 'XenForo Development Discussions' started by Lum, May 17, 2013.

  1. Lum

    Lum Member

    Hi, I'm trying to write a Wordpress -> XenForo account bridge, so am trying to edit users programatically using the DataWriter, and am running into issues with custom user fields. How would I write to the default custom fields, aka "aim" and "yahoo"?

    This code

            $sUsername = str_replace(' ', "_", $WP_User->user_login);
            $dbUserModel = XenForo_Model::create('XenForo_Model_User');
            $cUserInfo = $dbUserModel->getUserByName($sUsername);
            $iUserID = $cUserInfo['user_id'];
            if($iUserID) {
                $cWriter = XenForo_DataWriter::create('XenForo_DataWriter_User');
                $cWriter->set('aim', $WP_User->aim);
                $cWriter->set('yahoo', $WP_User->yim);
    throws this error
    An exception occurred: The field 'aim' was not recognised. in /Users/sjennings/Perforce/sjennings_mac/URPG/SotAWebsite/forum/library/XenForo/DataWriter.php on line 1321
        XenForo_DataWriter->_haveErrorsPreventSave() in /Users/sjennings/Perforce/sjennings_mac/URPG/SotAWebsite/forum/library/XenForo/DataWriter.php at line 1363
        XenForo_DataWriter->save() in /Users/sjennings/Perforce/sjennings_mac/URPG/SotAWebsite/wp-content/mu-plugins/xenforo.php at line 126
    Thanks for your help!
  2. tyteen4a03

    tyteen4a03 Well-Known Member

    Use XenForo_DataWriter_User->setCustomFields.
  3. Lum

    Lum Member

    That got me on the right track, thanks!

Share This Page