Support » Plugin: User Avatar » [Plugin: User Avatar] remove orphaned directories in avatar upload path

  • 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/

Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: User Avatar] remove orphaned directories in avatar upload path’ is closed to new replies.