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/link-template.php

    r31545 r31561  
    34233423 *     Optional. Arguments to return instead of the default arguments.
    34243424 *
    3425  *     @type int    $size           Height and width of the avatar in pixels. Default 96.
     3425 *     @type int    $size           Height and width of the avatar image file in pixels. Default 96.
     3426 *     @type int    $height         Display height of the avatar in pixels. Defaults to $size.
     3427 *     @type int    $width          Display width of the avatar in pixels. Defaults to $size.
    34263428 *     @type string $default        URL for the default image or a default type. Accepts '404' (return
    34273429 *                                  a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster),
     
    34373439 *     @type array  $processed_args When the function returns, the value will be the processed/sanitized $args
    34383440 *                                  plus a "found_avatar" guess. Pass as a reference. Default null.
     3441 *     @type string $extra_attr     HTML attribute to insert in the IMG element.  Has no default and is not sanitized.
    34393442 * }
    34403443 *
     
    34503453    $args = wp_parse_args( $args, array(
    34513454        'size'           => 96,
     3455        'height'         => null,
     3456        'width'          => null,
    34523457        'default'        => get_option( 'avatar_default', 'mystery' ),
    34533458        'force_default'  => false,
     
    34553460        'scheme'         => null,
    34563461        'processed_args' => null, // if used, should be a reference
     3462        'extra_attr'     => '',
    34573463    ) );
    34583464
     
    34643470    } else {
    34653471        $args['size'] = 96;
     3472    }
     3473
     3474    if ( is_numeric( $args['height'] ) ) {
     3475        $args['height'] = absint( $args['height'] );
     3476        if ( ! $args['height'] ) {
     3477            $args['height'] = $args['size'];
     3478        }
     3479    } else {
     3480        $args['height'] = $args['size'];
     3481    }
     3482
     3483    if ( is_numeric( $args['width'] ) ) {
     3484        $args['width'] = absint( $args['width'] );
     3485        if ( ! $args['width'] ) {
     3486            $args['width'] = $args['size'];
     3487        }
     3488    } else {
     3489        $args['width'] = $args['size'];
    34663490    }
    34673491
Note: See TracChangeset for help on using the changeset viewer.