Skip to:
Content

BuddyPress.org

Ticket #6586: 6586.patch

File 6586.patch, 3.0 KB (added by imath, 9 years ago)
  • src/bp-core/bp-core-avatars.php

    diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php
    index fb74fee..733b5f0 100644
    function bp_core_set_avatar_constants() { 
    3030        if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) )
    3131                define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
    3232
     33        if ( ! defined( 'BP_AVATAR_ORIGINAL_MOBILE_MAX_WIDTH' ) ) {
     34                define( 'BP_AVATAR_ORIGINAL_MOBILE_MAX_WIDTH', 280 );
     35        }
     36
    3337        if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
    3438
    3539                $fileupload_maxk = bp_core_get_root_option( 'fileupload_maxk' );
    function bp_core_set_avatar_globals() { 
    6569        $bp->avatar->full->height  = BP_AVATAR_FULL_HEIGHT;
    6670
    6771        // Upload maximums
    68         $bp->avatar->original_max_width    = BP_AVATAR_ORIGINAL_MAX_WIDTH;
    69         $bp->avatar->original_max_filesize = BP_AVATAR_ORIGINAL_MAX_FILESIZE;
     72        $bp->avatar->original_max_width        = BP_AVATAR_ORIGINAL_MAX_WIDTH;
     73        $bp->avatar->original_max_mobile_width = BP_AVATAR_ORIGINAL_MOBILE_MAX_WIDTH;
     74        $bp->avatar->original_max_filesize     = BP_AVATAR_ORIGINAL_MAX_FILESIZE;
    7075
    7176        // Defaults
    7277        $bp->avatar->thumb->default = bp_core_avatar_default_thumb();
    function bp_core_avatar_original_max_width() { 
    16871692}
    16881693
    16891694/**
     1695 * Get the max width for original avatar uploads for mobile devices.
     1696 *
     1697 * @since BuddyPress (2.4.0)
     1698 *
     1699 * @return int The max width for original avatar uploads.
     1700 */
     1701function bp_core_avatar_original_max_mobile_width() {
     1702
     1703        /**
     1704         * Filters the max width for original avatar uploads for mobile devices.
     1705         *
     1706         * @since BuddyPress (2.4.0)
     1707         *
     1708         * @param int $value Value for the max width.
     1709         */
     1710        return apply_filters( 'bp_core_avatar_original_max_mobile_width', (int) buddypress()->avatar->original_max_mobile_width );
     1711}
     1712
     1713/**
    16901714 * Get the max filesize for original avatar uploads.
    16911715 *
    16921716 * @since BuddyPress (1.5.0)
  • src/bp-core/classes/class-bp-attachment-avatar.php

    diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php
    index f003b65..b9e6d94 100644
    class BP_Attachment_Avatar extends BP_Attachment { 
    130130                $size   = @getimagesize( $file );
    131131                $retval = false;
    132132
     133                // Defaults to original max width
     134                $original_max_width = bp_core_avatar_original_max_width();
     135
     136                // Check if mobile and eventually adapt the max width
     137                if ( wp_is_mobile() ) {
     138                        $original_max_width = bp_core_avatar_original_max_mobile_width();
     139                }
     140
    133141                // Check image size and shrink if too large
    134                 if ( $size[0] > bp_core_avatar_original_max_width() ) {
     142                if ( $size[0] > $original_max_width ) {
    135143                        $editor = wp_get_image_editor( $file );
    136144
    137145                        if ( ! is_wp_error( $editor ) ) {
    138146                                $editor->set_quality( 100 );
    139147
    140                                 $resized = $editor->resize( bp_core_avatar_original_max_width(), bp_core_avatar_original_max_width(), false );
     148                                $resized = $editor->resize( $original_max_width, $original_max_width, false );
    141149                                if ( ! is_wp_error( $resized ) ) {
    142150                                        $thumb = $editor->save( $editor->generate_filename() );
    143151                                } else {