WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#11880 closed enhancement (fixed)

Avatars in Custom Comment Type

Reported by: usermrpapa Owned by: nacin
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9.1
Component: Comments Keywords: has-patch, tested
Focuses: Cc:

Description

currently, its possible to define a custom comment type and have them displayed interspersed within normal WP comments or in its own section.

However, since the comment_type is custom, the get_avatar() function wont show avatars because of an explicit check for comment_type of comment. A comment in the code says dont show avatars for pingbacks or trackbacks which makes sense, but it also ruins the chance to show avatars for custom comment types. Also, the check and abort is before the avatar filter, so no chance to override.

Sure would be nice if this statement:


             if ( isset($id_or_email->comment_type) && '' != $id_or_email->comment_type && 'comment' != $id_or_email->comment_type )

didnt explicitly check for comment_type of 'comment' only and instead checked for types not wanted (ie pingback or trackback).

will try to work up a patch tonight.

Attachments (1)

avatar-r12716.patch (798 bytes) - added by usermrpapa 10 years ago.
patch to display avatar on custom comment type

Download all attachments as: .zip

Change History (11)

#1 @nacin
10 years ago

Should probably be a filter that passes the comment_type.

That said, this function is actually pluggable, you could replace the entire get_avatar() function when implementing your custom comment type.

#2 @usermrpapa
10 years ago

while pluggable, really hate it as its a maintainability issue... hate checking every version to see if there is a needed change...

not sure I follow the filter comment on comment_type... in the if statement?

#3 @nacin
10 years ago

If we change this, any custom comment type will suddenly have gravar support, *and* there will be no way to turn it off without overriding get_avatar().

Something like:

if ( isset($id_or_email->comment_type)
   && '' != $id_or_email->comment_type
   && ! in_array( $id_or_email->comment_type,
      apply_filters( 'get_avatar_comment_types', array( 'comment' ), $id_or_email->comment_type ) ) )

Kind of messy, but it allows for a plugin to add to a whitelist of comment types that should support get_avatar().

#4 @usermrpapa
10 years ago

thought thats what you might be saying. will play with that tonight and then work up a patch if it goes well. Thanks!

@usermrpapa
10 years ago

patch to display avatar on custom comment type

#5 @usermrpapa
10 years ago

  • Keywords has-patch added

works nicely in letting custom comment types display avatar. patch against trunk r12716 attached...

#6 @usermrpapa
10 years ago

  • Keywords tested added

#7 @nacin
10 years ago

Looks good, I would probably split it into two lines of code instead of wrapping it for clarity. Also, the code currently in core could simply use !empty(). This logic should work:

// No avatar for pingbacks or trackbacks
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
if ( !empty( $id_or_email->comment_type ) && !in_array( 'get_avatar_comment_types', $allowed_comment_types ) )
	return false;

#8 @usermrpapa
9 years ago

any chance this will make 3.0?

#9 @nacin
9 years ago

  • Owner set to nacin
  • Status changed from new to accepted

#10 @nacin
9 years ago

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

(In [13231]) Add filter to get_avatar() to allow avatars for custom comment types. Props usermrpapa. Fixes #11880

Note: See TracTickets for help on using tickets.