Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#20285 closed defect (bug) (fixed)

Author meta fields aren't displaying correctly due to broken logic

Reported by: fredwu's profile FredWu Owned by: ryan's profile ryan
Milestone: 3.4 Priority: high
Severity: major Version: 3.3.1
Component: Users Keywords: has-patch
Focuses: Cc:


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;
		$authordata = get_userdata( $user_id );


	// 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;
		$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)

author_metadata_fix.patch (594 bytes) - added by FredWu 12 years ago.
author_metadata_fix2.patch (561 bytes) - added by fredwu 12 years ago.
20285.diff (933 bytes) - added by scribu 12 years ago.
20285.2.diff (1.4 KB) - added by ryan 12 years ago.

Download all attachments as: .zip

Change History (19)

#1 @FredWu
12 years ago

  • Severity changed from major to normal

#2 follow-up: @scribu
12 years ago

  • Cc scribu added

You can just replace isset() with !empty() since empty() doesn't cause a notice.

Last edited 12 years ago by scribu (previous) (diff)

#3 in reply to: ↑ 2 @fredwu
12 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.

#4 @scribu
12 years ago

  • Milestone changed from Awaiting Review to 3.4

12 years ago

#5 @scribu
12 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 @nacin
12 years ago

  • Milestone changed from 3.4 to 3.3.2
  • Priority changed from normal to high
  • Severity changed from normal to major

#7 @ryan
12 years ago

Added some author tests:

20285.diff fails for get_the_author_meta( 'login' ). Perhaps we should add some shorthand mappings to WP_User::back_compat_keys.

#8 @nacin
12 years ago

Tests well. Fine with me.

12 years ago

#9 @ryan
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 @ryan
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.

#12 @nacin
12 years ago

  • Milestone changed from 3.3.2 to 3.4

#13 @ryan
12 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [20565]:

Remove key mangling code from get_the_author_meta(). Make it more inline with get_user_option(). Handle collision with old users table columns that are on old schema, particularly user_description.

Props scribu, fredwu.
Fixes #20285

#15 @nacin
12 years ago

In [20575]:

Fix a notice in [20565] where get_the_author_meta() may be called prior to postdata from being set up. In this case, the function should return nothing (via the filter). props johnjamesjacoby. fixes #20529. see #20285.

Note: See TracTickets for help on using tickets.