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_ | 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)
Change History (8)
#3
@
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
@
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
#5
@
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...
There is a serious typo in my above replacement function, sorry: