1. /* Lines 260 to 293: */
  2.  
  3.     /* Move the file to the correct upload location. */
  4.     if ( !empty( $bp->avatar_admin->original['error'] ) ) {
  5.         bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
  6.         return false;
  7.     }
  8.  
  9.     /* Resize the image down to something manageable and then delete the original */
  10.     /* HACK made some changes to check image parameters more carefully */
  11.     $_size = getimagesize( $bp->avatar_admin->original['file'] );
  12.     if ( $_size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
  13.         $_thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
  14.         // Need to check if upload succeeded - issue with small files!
  15.         if ( is_object($_thumb) && get_class($_thumb) == 'WP_Error' ) {
  16.             bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $_thumb->get_error_message()), 'error');
  17.         return false;
  18.         }
  19.         $bp->avatar_admin->resized = $_thumb;
  20.     }
  21.  
  22.     $bp->avatar_admin->image = new stdClass;
  23.  
  24.     /* We only want to handle one image after resize. */
  25.     if ( empty( $bp->avatar_admin->resized ) )
  26.         $bp->avatar_admin->image->dir = $bp->avatar_admin->original['file'];
  27.     else {
  28.         $bp->avatar_admin->image->dir = $bp->avatar_admin->resized;
  29.         @unlink( $bp->avatar_admin->original['file'] );
  30.     }
  31.  
  32.     /* Set the url value for the image */
  33.     $bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, BP_AVATAR_URL, $bp->avatar_admin->image->dir );
  34.  
  35.     return true;
  36. }