Make WordPress Core


Ignore:
Timestamp:
02/26/2015 09:16:02 PM (10 years ago)
Author:
wonderboymusic
Message:

In get_avatar_data() and get_avatar(), allow height and width to be specified separately (both default to size). Also allow arbitrary attributes on the <img> via the extra_attr arg.

Props miqrogroove.
See #31469.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r31480 r31561  
    21022102 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
    21032103 *                           user email, WP_User object, WP_Post object, or comment object.
    2104  * @param int    $size       Optional. Height and width of the avatar in pixels. Default 96.
     2104 * @param int    $size       Optional. Height and width of the avatar image file in pixels. Default 96.
    21052105 * @param string $default    Optional. URL for the default image or a default type. Accepts '404'
    21062106 *                           (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
     
    21132113 *     Optional. Extra arguments to retrieve the avatar.
    21142114 *
     2115 *     @type int          $height        Display height of the avatar in pixels. Defaults to $size.
     2116 *     @type int          $width         Display width of the avatar in pixels. Defaults to $size.
    21152117 *     @type bool         $force_default Whether to always show the default image, never the Gravatar. Default false.
    21162118 *     @type string       $rating        What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
     
    21222124 *     @type bool         $force_display Whether to always show the avatar - ignores the show_avatars option.
    21232125 *                                       Default false.
     2126 *     @type string       $extra_attr    HTML attribute to insert in the IMG element.  Has no default and is not sanitized.
    21242127 * }
    21252128 *
     
    21302133        // get_avatar_data() args.
    21312134        'size'          => 96,
     2135        'height'        => null,
     2136        'width'         => null,
    21322137        'default'       => get_option( 'avatar_default', 'mystery' ),
    21332138        'force_default' => false,
     
    21372142        'class'         => null,
    21382143        'force_display' => false,
     2144        'extra_attr'    => '',
    21392145    );
    21402146
     
    21482154
    21492155    $args = wp_parse_args( $args, $defaults );
     2156
     2157    if ( empty( $args['height'] ) ) {
     2158        $args['height'] = $args['size'];
     2159    }
     2160    if ( empty( $args['width'] ) ) {
     2161        $args['width'] = $args['size'];
     2162    }
    21502163
    21512164    /**
     
    21942207
    21952208    $avatar = sprintf(
    2196         "<img alt='%s' src='%s' class='%s' height='%d' width='%d' />",
     2209        "<img alt='%s' src='%s' class='%s' height='%d' width='%d' %s/>",
    21972210        esc_attr( $args['alt'] ),
    21982211        esc_url( $url ),
    21992212        esc_attr( join( ' ', $class ) ),
    2200         (int) $args['size'],
    2201         (int) $args['size']
     2213        (int) $args['height'],
     2214        (int) $args['width'],
     2215        $args['extra_attr']
    22022216    );
    22032217
Note: See TracChangeset for help on using the changeset viewer.