WordPress.org

Ready to get started?Download WordPress

Forums

User Avatar
remove orphaned directories in avatar upload path (2 posts)

  1. hkellecioglu
    Member
    Posted 2 years ago #

    Hi,
    When user deletes his avatar 'user_avatar_delete_files' function can't remove user avatar directory because of the cache sub directory.

    I changed the 'user_avatar_delete_files' so it can remove subdirectories.

    function user_avatar_delete_files($uid) {
    	$avatar_folder_dir = USER_AVATAR_UPLOAD_PATH."{$uid}/";
    	if ( !file_exists( $avatar_folder_dir ) )
    		return false;
    
    	if ( is_dir( $avatar_folder_dir ) && $av_dir = opendir( $avatar_folder_dir ) ) {
    		while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
                if( $avatar_file != '.' && $avatar_file != '..' && is_dir( $avatar_folder_dir . $avatar_file ) && $sub_dir = opendir( $avatar_folder_dir . $avatar_file ) ) {
                    while ( false !== ( $subdir_file = readdir($sub_dir) ) ) {
                        @unlink( $avatar_folder_dir . $avatar_file . '/' .  $subdir_file );
                    }
    
                    closedir($sub_dir);
                    @rmdir( $avatar_folder_dir . $avatar_file );
    
                } else {
                    @unlink( $avatar_folder_dir . '/' . $avatar_file );
                }
    		}
    
    		closedir($av_dir);
    	}
    
    	@rmdir( $avatar_folder_dir );
    
    }

    Also when user account deleted, this function can be fired by 'delete_user' hook to remove orphaned avatar directory.

    add_action( 'delete_user', 'user_avatar_delete_files' );

    May be developers add this functionalities to next release.

    http://wordpress.org/extend/plugins/user-avatar/

  2. dikkevandale
    Member
    Posted 1 year ago #

    What does this exactly do? I'm looking for a solutions that deletes images created in the /wp-upload/DD/MM/ folder. The plugin leaves midsize-xxxx.jpg images on the FTP every time a picture is uploaded.. This is annoying.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.