#20285 closed defect (bug) (fixed)
Author meta fields aren't displaying correctly due to broken logic
Reported by: | FredWu | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.4 | Priority: | high |
Severity: | major | Version: | 3.3.1 |
Component: | Users | Keywords: | has-patch |
Focuses: | Cc: |
Description
Some authors have missing meta data even though the data are in the database. For example, some authors' description/biography are empty when retrieving them from the_author_meta('description')
, even though $authordata->description
from the function shows the data correctly.
This is caused by a bug in wp-includes/author-template.php
, starting from line 99:
function get_the_author_meta($field = '', $user_id = false) { if ( ! $user_id ) global $authordata; else $authordata = get_userdata( $user_id ); var_dump($authordata); // Keys used as object vars cannot have dashes. $field = str_replace('-', '', $field); $field = strtolower($field); $user_field = "user_$field"; if ( 'id' == $field ) $value = isset($authordata->ID) ? (int)$authordata->ID : 0; elseif ( isset($authordata->$user_field) ) $value = $authordata->$user_field; else $value = isset($authordata->$field) ? $authordata->$field : ''; return apply_filters('get_the_author_' . $field, $value, $user_id); }
elseif ( isset($authordata->$user_field) )
is the problem, because for some users this field is set, but is empty, so the system never gets through to the real 'description' field.
I've attached a patch that fixes this.
Attachments (4)
Change History (19)
#3
in reply to:
↑ 2
@
13 years ago
Replying to scribu:
You can just replace
isset()
with!empty()
since empty() doesn't cause a notice.
Good point! I've attached the updated patch.
#5
@
13 years ago
I just realised we missed cleaning up get_the_author_meta() in #15458. All the logic is duplicated in WP_User::__get()
. Fixed in 20285.diff.
#6
@
13 years ago
- Milestone changed from 3.4 to 3.3.2
- Priority changed from normal to high
- Severity changed from normal to major
#7
@
12 years ago
Added some author tests:
http://unit-tests.trac.wordpress.org/changeset/691
20285.diff fails for get_the_author_meta( 'login' ). Perhaps we should add some shorthand mappings to WP_User::back_compat_keys.
#9
@
12 years ago
20285.2.diff does the mapping in get_the_author_meta() instead of in WP_User::back_compat_keys to reduce the possibility of unintended consequences for 3.3.2.
#11
@
12 years ago
To reproduce this, you must have a users table that still has user_description in the schema. user_description hasn't been in the users table since 2.0. Somehow the schema for the users table in question has not been updated for a long time.
For the case of user_description existing in meta, 3.3.1 already correctly handles mapping this to description.
You can just replace
isset()
with!empty()
since empty doesn't cause a notice.