Ticket #37773: 37773.2.diff
| File 37773.2.diff, 3.6 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/pluggable.php
2420 2420 * 2421 2421 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, 2422 2422 * user email, WP_User object, WP_Post object, or WP_Comment object. 2423 * @param int $sizeOptional. Height and width of the avatar image file in pixels. Default 96.2423 * @param int|string $size Optional. Height and width of the avatar image file in pixels. Default 96. 2424 2424 * @param string $default Optional. URL for the default image or a default type. Accepts '404' 2425 2425 * (return a 404 instead of a default image), 'retro' (8bit), 'monsterid' 2426 2426 * (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"), … … 2466 2466 $args = array(); 2467 2467 } 2468 2468 2469 $args['size'] = (int) $size; 2469 // At this point, $size can be either a string or an integer. 2470 $args['size'] = $size; 2470 2471 $args['default'] = $default; 2471 2472 $args['alt'] = $alt; 2472 2473 2473 2474 $args = wp_parse_args( $args, $defaults ); 2474 2475 2476 // Check for valid registered WordPress image size values. 2477 if ( is_string( $size ) && in_array( $size, get_intermediate_image_sizes() ) ) { 2478 // Set the height and width to the dimensions established by the registered WordPress image size. 2479 $args['height'] = get_option( "{$size}_size_h" ); 2480 $args['width'] = get_option( "{$size}_size_w" ); 2481 2482 // Height and width weren't assigned in the last step because the image size is custom. 2483 if ( empty( $args['height'] ) || empty( $args['width'] ) ) { 2484 $sizes = wp_get_additional_image_sizes(); 2485 2486 if ( isset( $sizes[ $size ] ) ) { 2487 $args['height'] = $sizes[ $size ]['height']; 2488 $args['width'] = $sizes[ $size ]['width']; 2489 } 2490 } 2491 } 2492 2475 2493 if ( empty( $args['height'] ) ) { 2476 $args['height'] = $args['size'];2494 $args['height'] = (int) is_numeric( $size ) ? $size : $defaults['size']; 2477 2495 } 2496 2478 2497 if ( empty( $args['width'] ) ) { 2479 $args['width'] = $args['size'];2498 $args['width'] = (int) is_numeric( $size ) ? $size : $defaults['size']; 2480 2499 } 2481 2500 2482 2501 if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { … … 2503 2522 return apply_filters( 'get_avatar', $avatar, $id_or_email, $args['size'], $args['default'], $args['alt'], $args ); 2504 2523 } 2505 2524 2525 // Not filtering pre_get_avatar, so revert to Gravatar square sizing. Reset the size to the height in case it is a string. 2526 $args['width'] = $args['height']; 2527 $args['size'] = $args['height']; 2528 2506 2529 if ( ! $args['force_display'] && ! get_option( 'show_avatars' ) ) { 2507 2530 return false; 2508 2531 } -
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)