I am trying to update a user programmatically in Drupal 7.

User records have multiple custom fields, configured via admin interface #overlay=admin/config/people/accounts/fields

My code sets text and datetime fields fine, but fails to update a phone number field.

Error message:

EntityMetadataWrapperException: Unknown data property field_mobilephone.
in EntityStructureWrapper->getPropertyInfo()
(line 335 of /Applications/MAMP/htdocs/sites/all/modules/entity/includes/entity.wrapper.inc)


  $new_user = user_save(null, $fields);

  $obj = entity_metadata_wrapper('user', $new_user);

When I do var_dump($obj) I can see all configured text fields in the output, but not the phone number fields.

Field type is 'phone number', provided by the cck_phone-7.x-1.x-dev module (I couldn't find any other place where it could come from).

So question is how do I set phone number field via entity_metadata_wrapper?

  • What type of field phone number field is? Is text too? is a field type provided by a module?
    – sanzante
    Commented Jul 9, 2014 at 9:03
  • It is of type 'phone number', provided by cck_phone-7.x-1.x-dev. I've updated the question. Commented Jul 9, 2014 at 10:16
  • $obj->field_mobilephone->set(array('number' => $_REQUEST['mobilephone']));?
    – Clive
    Commented Jul 9, 2014 at 10:38
  • @Clive, that doesn't work because even simplest $obj->field_mobilephone; produces the same EntityMetadataWrapperException: Unknown data property field_mobilephone Commented Jul 10, 2014 at 4:23

1 Answer 1


I got around this problem by using the following snippet just before the user_save(..) call:

$fields['field_mobilephone'][LANGUAGE_NONE][0]['number'] = $_REQUEST['mobilephone'];
$fields['field_mobilephone'][LANGUAGE_NONE][0]['country_codes'] = 'au';

This approach bypasses the entity_metadata_wrapper altogether. Pretty sure there's a cleaner way, but I'm not yet aware of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.