Make WordPress Core

Opened 7 years ago

Last modified 6 years ago

#40518 new enhancement

multisite users table should use user's ID to get the avatar

Reported by: mc256's profile mc256 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.4
Component: Users Keywords:
Focuses: multisite Cc:

Description

In class-wp-users-list-tables.php, the get_avatar() uses WP_User 's ID.

<?php
                $avatar = get_avatar( $user_object->ID, 32 );

                // Comma-separated list of user roles.
                $roles_list = implode( ', ', $user_roles );

                $r = "<tr id='user-$user_object->ID'>";

(around line 438)

However, in class-wp-ms-users-list-table.php, the get_avatar() uses WP_User 's email address.

<?php

                $super_admins = get_super_admins();
                $avatar = get_avatar( $user->user_email, 32 );
                $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );

                echo $avatar;

(around line 238)

In my opinion, class-wp-ms-users-list-table.php should have the same behaviour. And we have already known that the user has been registered. So we should better use the User's ID.

Change History (6)

#1 @mc256
7 years ago

  • Component changed from General to Networks and Sites

This ticket was mentioned in Slack in #core-multisite by mc256. View the logs.


7 years ago

#3 @SergeyBiryukov
7 years ago

  • Component changed from Networks and Sites to Users

#4 follow-up: @keraweb
6 years ago

In fact, looking at the code in get_avatar_data, it looks like using an email address is even more logical since that doesn't require querying a user at all.

The first parameter can also be the user object itself, or a post / comment object where it will look for the author so the usage of this function differs a lot within the WP core base. In the end all it needs to get the avatar is the email address, nothing more (since gravatar is based on the email address).

#5 @keraweb
6 years ago

Related: #41544

#6 in reply to: ↑ 4 @mc256
6 years ago

Replying to keraweb:

In fact, looking at the code in get_avatar_data, it looks like using an email address is even more logical since that doesn't require querying a user at all.

The first parameter can also be the user object itself, or a post / comment object where it will look for the author so the usage of this function differs a lot within the WP core base. In the end all it needs to get the avatar is the email address, nothing more (since gravatar is based on the email address).

This is a ticket posted almost two years ago. LOL

I wrote a plugin that allows user uploading the avatar if they want. This inconsistency really breaks my plugin. I think it should be more accurate. You should not assume that the avatar is based on the email address.

Thank you for replying my ticket.

Note: See TracTickets for help on using tickets.