Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#7494 closed defect (bug) (fixed)

registered members displayed as "anonymous" in comments if display_name empty (has fix)

Reported by: _ck_'s profile _ck_ Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.6
Component: General Keywords: has-patch
Focuses: Cc:

Description

There is a bug since WP 1.5 where if the display_name is empty when a comment is posted, WordPress does not fall back to the user_login but instead saves the comment_author as blank. This causes the comment template to display registered members as "anonymous".

While typically in WordPress the stored display_name would not be blank, other software that shares the user table such as bbPress does not save a display_name by default during it's registration process. I am unsure if this is an attempt to save database space, but it makes sense since if the display_name == the user_login, why duplicate the data (on a million users, this would add up significantly).

The bug is being addressed on the bbPress side:
http://trac.bbpress.org/ticket/922

however, why not take the opportunity to fix the bug on the WordPress side as well:

it is caused by line 43 in wp-comment-post.php in WP 2.6.1

if ( $user->ID ) {
	$comment_author       = $wpdb->escape($user->display_name);

Should be changed to something like:

if ( $user->ID ) {
if (empty($user->display_name)) 	{$user->display_name=$user->user_login;}
$comment_author       = $wpdb->escape($user->display_name);

The above fix of course does not fix existing entries of course.
To do that, the function get_comment_author in comment-template.php must be augmented with similar code.

function get_comment_author() {
	global $comment;
if (empty($comment->comment_author) && !empty($comment->user_id)) {$user=get_userdata($comment->user_id); $author=$user->user_login;}

	if ( empty($comment->comment_author) ) {
                if (!empty($comment->user_id) ) {
                     $author=$user->user_login;
                } else {$author = __('Anonymous');}
	} else {
		$author = $comment->comment_author;
        }
	return apply_filters('get_comment_author', $author);
}

Attachments (2)

wp-comments-post.diff (480 bytes) - added by mrmist 16 years ago.
wp-comments-post patch against 8772
comment-template.diff (604 bytes) - added by mrmist 16 years ago.
wp-includes\comment-template patch against 8772

Download all attachments as: .zip

Change History (8)

#1 @_ck_
16 years ago

There is a serious typo in my above replacement function, sorry:

function get_comment_author() {
	global $comment;

	if ( empty($comment->comment_author) ) {
              if (!empty($comment->user_id)){ 
                     $user=get_userdata($comment->user_id);       
                     $author=$user->user_login;
                } else {$author = __('Anonymous');}
	} else {
		$author = $comment->comment_author;
        }
	return apply_filters('get_comment_author', $author);
}

#2 @_ck_
16 years ago

  • Milestone changed from 2.7 to 2.6.1

#3 @santosj
16 years ago

It doesn't matter if it is there or not, the space is still being used. Whether it is padded because it is empty or filled with data. The space used will still be the same.

#4 @westi
16 years ago

  • Milestone changed from 2.6.1 to 2.6.2

2.6.1 has been released, moving to 2.6.2 milestone

@mrmist
16 years ago

wp-comments-post patch against 8772

#5 @mrmist
16 years ago

  • Keywords has-patch added

Added patch files for the suggested alterations, though I'm not convinced that there is the right place to be doing this - would probably be better to fix plugins that are not filling in display names, or alter the methods they are using so that they fill in all the info when setting up / importing new users...

@mrmist
16 years ago

wp-includes\comment-template patch against 8772

#6 @markjaquith
15 years ago

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

(In [9781]) Handle blank display_name for commenters. props mrmist. fixes #7494

Note: See TracTickets for help on using tickets.