#19540 closed defect (bug) (worksforme)
get_userdata() doesn't include meta values in 'data' property
Reported by: | beautomated | Owned by: | otto |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 3.3 |
Component: | Users | Keywords: | |
Focuses: | Cc: |
Description
The following code worked in v3.2.1 and broke in v3.3. The custom meta value for "company" is empty, returning 'N/A' instead of what it should be: 'ABC Corporation'.
update_user_meta(get_current_user_id(), 'company', 'ABC Corporation');
$users = get_users(array('role' => 'administrator'));
foreach ($users as $user) {
$user = get_userdata($user->ID);
$company = (property_exists($user, 'company') && ($val = $user->company)) ? $val : 'N/A';
echo "You work for {$company}<br />";
}
Change History (3)
#1
@
13 years ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
#2
@
13 years ago
Thanks, Otto. This solution did work for two of our client projects. Note that I'm not comfortable with the notion of "Magic" properties, nor changes in the API without deprecation. I don't think any hidden properties are helpful to developers who don't already know about them. Nevertheless, I really appreciate the help and it did work for us. Thank you.
If you use
isset( $user->company )
, it will work and be compatible with both WP 3.2 and 3.3.For more info, see #15458