Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/20/2014 09:27:47 PM (10 years ago)
Author:
boonebgorges
Message:

Sanity check before deleting old avatar files before cropping new ones

Previously, if a user uploaded a new avatar file that had a name format like
an existing BP avatar file, BP would accidentally wipe that file out before
cropping. This would result in a failed crop, because the just-uploaded image
would be gone. This changeset introduces a sanity check: only delete existing
avatar files if the filename for those files is not the same as the uploaded
file.

Fixes #5417

File:
1 edited

Legend:

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

    r7769 r7943  
    751751
    752752    // Delete the existing avatar files for the object
    753     bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
     753    $existing_avatar = bp_core_fetch_avatar( array(
     754        'object'  => $object,
     755        'item_id' => $item_id,
     756        'html' => false,
     757    ) );
     758
     759    if ( ! empty( $existing_avatar ) ) {
     760        // Check that the new avatar doesn't have the same name as the
     761        // old one before deleting
     762        $upload_dir           = wp_upload_dir();
     763        $existing_avatar_path = str_replace( $upload_dir['baseurl'], '', $existing_avatar );
     764        $new_avatar_path      = str_replace( $upload_dir['basedir'], '', $original_file );
     765
     766        if ( $existing_avatar_path !== $new_avatar_path ) {
     767            bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
     768        }
     769    }
     770
     771
    754772
    755773    // Make sure we at least have a width and height for cropping
Note: See TracChangeset for help on using the changeset viewer.