[wp-trac] [WordPress Trac] #7494: registered members displayed as "anonymous" in comments if display_name empty (has fix)

WordPress Trac wp-trac at lists.automattic.com
Mon Aug 11 10:25:29 GMT 2008


#7494: registered members displayed as "anonymous" in comments if display_name
empty (has fix)
---------------------+------------------------------------------------------
 Reporter:  _ck_     |       Owner:  anonymous
     Type:  defect   |      Status:  new      
 Priority:  normal   |   Milestone:  2.7      
Component:  General  |     Version:  2.6      
 Severity:  normal   |    Keywords:           
---------------------+------------------------------------------------------
 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);
 }

 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7494>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list