Skip to:
Content

BuddyPress.org

Changeset 10754


Ignore:
Timestamp:
05/14/2016 04:48:29 AM (10 years ago)
Author:
boonebgorges
Message:

Default no_grav avatars should be thumb-sized when appropriate.

mystery-man-50.jpg should be served when:

  • A 'thumb' is requested, and the thumb width set in the config is 50 pixels or less, or
  • An avatar with a width of 50 or less is requested.

Props r0z.
Fixes #7056.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-avatars.php

    r10721 r10754  
    18661866        // Use the local default image.
    18671867        } elseif ( 'local' === $type ) {
    1868                 $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man.jpg';
     1868                $size = '';
     1869                if (
     1870                        ( isset( $params['type'] ) && 'thumb' === $params['type'] && bp_core_avatar_thumb_width() <= 50 ) ||
     1871                        ( isset( $params['width'] ) && $params['width'] <= 50 )
     1872                ) {
     1873
     1874                        $size = '-50';
     1875                }
     1876
     1877                $avatar = buddypress()->plugin_url . "bp-core/images/mystery-man{$size}.jpg";
    18691878
    18701879        // Use Gravatar's mystery person as fallback.
    18711880        } else {
    1872                 $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&amp;s=' . bp_core_avatar_full_width();
     1881                $size = '';
     1882                if ( isset( $params['type'] ) && 'thumb' === $params['type'] ) {
     1883                        $size = bp_core_avatar_thumb_width();
     1884                } else {
     1885                        $size = bp_core_avatar_full_width();
     1886                }
     1887                $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&amp;s=' . $size;
    18731888        }
    18741889
  • trunk/tests/phpunit/testcases/core/avatars.php

    r10370 r10754  
    315315                return $types;
    316316        }
     317
     318        /**
     319         * @group BP7056
     320         */
     321        public function test_no_grav_default_should_respect_thumb_type() {
     322                $found = bp_core_fetch_avatar( array(
     323                        'item_id' => 12345,
     324                        'object' => 'user',
     325                        'type' => 'thumb',
     326                        'no_grav' => true,
     327                        'html' => false,
     328                ) );
     329
     330                $this->assertContains( 'mystery-man-50.jpg', $found );
     331        }
     332
     333        /**
     334         * @group BP7056
     335         */
     336        public function test_no_grav_default_should_return_thumb_avatar_for_small_enough_width() {
     337                $found = bp_core_fetch_avatar( array(
     338                        'item_id' => 12345,
     339                        'object' => 'user',
     340                        'type' => 'full',
     341                        'width' => '50',
     342                        'no_grav' => true,
     343                        'html' => false,
     344                ) );
     345
     346                $this->assertContains( 'mystery-man-50.jpg', $found );
     347        }
     348
     349        /**
     350         * @group BP7056
     351         */
     352        public function test_no_grav_default_should_return_full_avatar_for_thumb_when_thumb_width_is_too_wide() {
     353                add_filter( 'bp_core_avatar_thumb_width', array( $this, 'filter_thumb_width' ) );
     354                $found = bp_core_fetch_avatar( array(
     355                        'item_id' => 12345,
     356                        'object' => 'user',
     357                        'type' => 'thumb',
     358                        'no_grav' => true,
     359                        'html' => false,
     360                ) );
     361                remove_filter( 'bp_core_avatar_thumb_width', array( $this, 'filter_thumb_width' ) );
     362
     363                $this->assertContains( 'mystery-man.jpg', $found );
     364        }
     365
     366        public function filter_thumb_width() {
     367                return 51;
     368        }
    317369}
Note: See TracChangeset for help on using the changeset viewer.