Ticket #37773: 37773.1.diff
| File 37773.1.diff, 2.7 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/pluggable.php
2237 2237 * 2238 2238 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, 2239 2239 * user email, WP_User object, WP_Post object, or WP_Comment object. 2240 * @param int $sizeOptional. Height and width of the avatar image file in pixels. Default 96.2240 * @param int|string $size Optional. Height and width of the avatar image file in pixels. Default 96. 2241 2241 * @param string $default Optional. URL for the default image or a default type. Accepts '404' 2242 2242 * (return a 404 instead of a default image), 'retro' (8bit), 'monsterid' 2243 2243 * (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"), … … 2264 2264 * @return false|string `<img>` tag for the user's avatar. False on failure. 2265 2265 */ 2266 2266 function get_avatar( $id_or_email, $size = 96, $default = '', $alt = '', $args = null ) { 2267 // Check first for native WordPress image sizes. 2268 if ( is_string( $size ) ) { 2269 if ( in_array( $size, get_intermediate_image_sizes() ) ) { 2270 $dimensions = [ 2271 'height' => get_option( "{$size}_size_h" ), 2272 'width' => get_option( "{$size}_size_w" ), 2273 ]; 2274 2275 $size = (int) $dimensions['height'] > $dimensions['width'] ? $dimensions['height'] : $dimensions['width']; 2276 } else { 2277 // Not a registered WordPress image size. Revert to default. 2278 $size = is_numeric( $size ) ? $size : 96; 2279 } 2280 } 2281 2267 2282 $defaults = array( 2268 2283 // get_avatar_data() args. 2269 'size' => 96,2284 'size' => $size, 2270 2285 'height' => null, 2271 2286 'width' => null, 2272 2287 'default' => get_option( 'avatar_default', 'mystery' ), -
tests/phpunit/tests/avatar.php
229 229 return $this->fakeURL; 230 230 } 231 231 232 /** 233 * @ticket 37773 234 */ 235 public function test_get_avatar_same_size_by_int_or_string() { 236 $img1 = get_avatar( 1, 150 ); 237 $img2 = get_avatar( 1, 'thumbnail' ); 238 $this->assertEquals( $img1, $img2 ); 239 240 $img3 = get_avatar( 1, 300 ); 241 $img4 = get_avatar( 1, 'medium' ); 242 $this->assertEquals( $img3, $img4 ); 243 244 $img5 = get_avatar( 1, 1024 ); 245 $img6 = get_avatar( 1, 'large' ); 246 $this->assertEquals( $img5, $img6 ); 247 } 248 public function test_get_avatar_default_size_returned_if_string_size_is_not_registered() { 249 $img1 = get_avatar( 1 ); 250 $img2 = get_avatar( 1, 'not-a-registered-size' ); 251 252 $this->assertEquals( $img1, $img2 ); 253 } 232 254 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)