WordPress.org

Make WordPress Core

Opened 18 months ago

Closed 18 months ago

Last modified 18 months ago

#19540 closed defect (bug) (worksforme)

get_userdata() doesn't include meta values in 'data' property

Reported by: beautomated Owned by: otto
Priority: normal Milestone:
Component: Users Version: 3.3
Severity: major Keywords:
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)

comment:1 scribu18 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

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

comment:2 beautomated18 months 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.

comment:3 scribu18 months ago

You're welcome, but I'm not Otto. :P

Note: See TracTickets for help on using tickets.