Re: Avatar Upload Issues
Here is the code with more before or after:
/* Move the file to the correct upload location. */
if ( !empty( $bp->avatar_admin->original ) ) {
bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original ), 'error' );
return false;
}
/* Resize the image down to something manageable and then delete the original */
/* HACK made some changes to check image parameters more carefully */
$_size = getimagesize( $bp->avatar_admin->original );
if ( $_size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
$_thumb = wp_create_thumbnail( $bp->avatar_admin->original, BP_AVATAR_ORIGINAL_MAX_WIDTH );
// Need to check if upload succeeded - issue with small files!
if ( is_object($_thumb) && get_class($_thumb) == 'WP_Error' ) {
bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $_thumb->get_error_message()), 'error');
return false;
}
$bp->avatar_admin->resized = $_thumb;
}
$bp->avatar_admin->image = new stdClass;
/* We only want to handle one image after resize. */
if ( empty( $bp->avatar_admin->resized ) )
$bp->avatar_admin->image->dir = $bp->avatar_admin->original;
else {
$bp->avatar_admin->image->dir = $bp->avatar_admin->resized;
@unlink( $bp->avatar_admin->original );
}
/* Set the url value for the image */
$bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, BP_AVATAR_URL, $bp->avatar_admin->image->dir );
return true;
}