[wp-trac] [WordPress Trac] #41544: $id_or_email parameter in get_avatar filter needs to be more concrete

WordPress Trac noreply at wordpress.org
Thu Aug 3 11:42:33 UTC 2017


#41544: $id_or_email parameter in get_avatar filter needs to be more concrete
----------------------------+------------------------------
 Reporter:  dikiy_forester  |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Users           |     Version:
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+------------------------------
Changes (by knutsp):

 * version:  trunk =>


Comment:

 A user or user_id cannot always be passed to the filters, because there
 may not be registered user in case of a comment.

 In case an email is encountered in this parameter, it might be a
 commenting user that isn't logged in. You have to decide whether  you want
 to look it up or not, depending on your needs.

 I use something like this
 {{{#!php
 <?php
 if is_numeric( $id_or_email ) && $id_or_email > 0 {
     $user = get_user_by ( 'id', $id_or_email );
 } elseif ( is_email( $id_or_email ) ) {
     $user = get_user_by( 'email', $id_or_email );
 } elseif ( $id_or_email instanceof WP_Comment && $id_or_email->user_id > 0
 ) {
     $user = get_user_by( 'id', $id_or_email->user_id );
 } elseif ( $id_or_email instanceof WP_User && $id_or_email->ID > 0 ) {
     $user = $id_or_email;
 } else {
     $user = false;
 }
 if ( $user ) {
     // Do somthing based on the fact that we have a logged in user, or an
 email mapped to a user
 } else {
     // Do something based on $id_or_email being the email or gravatar hash
 of a not logged in commenter
 }
 }}}
 If `get_avatar()` should do something like this for you, should it look up
 the email to a user or not?

 Given the nature / signature of this function I think the "concrete" user
 (or not) should be left to the plugin or theme to decide, and hence, the
 filter parameters are ok.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41544#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list