How to programmatically set a custom field? I am trying to programmatically change a custom field in a user object and I'm having very little success. I want to just use a function to set the field for the object, like field_get_items, except a setter version.

It seems like I could do:

$account = user_load($GLOABALS['user']-&gt;uid);

$edit = array(
    'field_custom' =&gt; array(
        'und' =&gt; array(
            0 =&gt; array(
                'value' =&gt; $lead_id
            )
        )
    )
);

user_save($account, $edit)


But there must be a better way to do this.

Any help would be appreciated. Thanks!
Use the Entity module wrapper. 


  The entity API provides some wrapper classes you may use to easily deal with entities and to leverage the entity property information modules provided. With the help of the wrappers you can access the property information, loop over known properties, or just get/set the described data values, etc.


Install the Entity module and do something like:

$user = user_load($GLOBALS['user']-&gt;uid);
$obj = entity_metadata_wrapper('user', $user);
$obj-&gt;field_custom = $lead_id;
$obj-&gt;save();


$GLOBALS is http://php.net/manual/en/reserved.variables.globals.php