WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#12291 closed defect (bug) (fixed)

floated_admin_avatar makes it difficult to use other avatars

Reported by: Otto42 Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9.2
Component: Administration Keywords: has-patch commit
Focuses: Cc:

Description

The get_avatar function is quite clever. It can take several different types of input and produce a correct gravatar from it.

The three main things it accepts are: user ID, email address, and a comment object.

A function called "floated_admin_avatar" in wp-admin/includes/comment.php hooks itself onto the "comment_author" filter in the admin sections. The purpose of it is to float a tiny little avatar image anywhere the comment author name appears in the admin.

The problem is that the floated_admin_avatar function doesn't let the get_avatar function do its job. Instead, the floated_admin_avatar function looks at the comment object and pulls out the email or user id to pass down to get_avatar.

The end result of this is that comment avatars displayed in the admin section are always generated without having the full comment available to them.

This is a problem for plugins that want to modify comment avatars using other data.

For example, if a plugin were to tag a comment as having come from a specific facebook user, then it could hook the get_avatar filter, recognize the comment as having been made by a facebook user (perhaps using the comment metadata), and then change the avatar to a facebook avatar instead of a gravatar.

But plugins can only do that when they receive the entire comment. If it's getting just an email address, then there's no way for it to recognize what's what.

In other words, floated_admin_avatar() needs to stop looking inside the $comment and passing a string or number to get_avatar. This is so my Facebook and Twitter plugins can display avatars in the admin via the simple filters which they already have instead of having to go to absurd lengths by manually disconnecting the floated_admin_avatar function.

All that needs to happen is for this to replace the existing function and fix the problem:

function floated_admin_avatar( $name ) {
	global $comment;
	$avatar = get_avatar( $comment, 32 );
	return "$avatar $name";
}

Simple. Works. And it lets plugins do what they were supposed to do.

Attachments (1)

12291.diff (584 bytes) - added by Otto42 6 years ago.
make floating_admin_avatar work better with plugins

Download all attachments as: .zip

Change History (8)

comment:1 follow-up: @scribu6 years ago

Could you put that in the form of a patch?

@Otto426 years ago

make floating_admin_avatar work better with plugins

comment:2 in reply to: ↑ 1 @Otto426 years ago

  • Keywords has-patch added

Replying to scribu:

Could you put that in the form of a patch?

Done.

comment:3 @scribu6 years ago

  • Keywords commit added

comment:4 follow-up: @nacin6 years ago

Could this break anything?

comment:5 in reply to: ↑ 4 @Otto426 years ago

Replying to nacin:

Could this break anything?

Doubt it. Feel free to test though. It's only going to affect places where comment avatars will show in the admin screens.

The change should not be visible on the admin screen at all, but if you use a plugin that allows for alternative avatars, then those could start showing up in the admin screens properly (where they were not before).

comment:6 @westi6 years ago

This looks sensible.

get_avatar is quite happy to receive a comment object.

comment:7 @westi6 years ago

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

(In [13420]) Just pass the comment object to get_avatar in floated_admin_avatar rather than duplicating logic. Fixes #12291 props Otto42.

Note: See TracTickets for help on using tickets.