#20285 closed defect (bug) (fixed)
Author meta fields aren't displaying correctly due to broken logic
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | high | Milestone: | 3.4 |
| Component: | Users | Version: | 3.3.1 |
| Severity: | major | Keywords: | has-patch |
| Cc: | scribu |
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)
comment:2
follow-up:
↓ 3
scribu
— 15 months ago
- Cc scribu added
comment:3
in reply to:
↑ 2
fredwu
— 15 months 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.
comment:5
scribu
— 15 months 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.
comment:6
nacin
— 15 months ago
- Milestone changed from 3.4 to 3.3.2
- Priority changed from normal to high
- Severity changed from normal to major
comment:7
ryan
— 14 months 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.
comment:9
ryan
— 14 months 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.
comment:11
ryan
— 14 months 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.
comment:12
nacin
— 14 months ago
- Milestone changed from 3.3.2 to 3.4
comment:13
ryan
— 14 months ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [20565]:
comment:14
SergeyBiryukov
— 14 months ago
Follow-up: #20529
comment:15
nacin
— 14 months ago
In [20575]:
You can just replace isset() with !empty() since empty doesn't cause a notice.