Changed media upload path for plugin, but generates error & shows wrong url

While I can’t easily spot right now what is the cause of the bug, it is obvious that your approach is just wrong on two fronts

  1. The uploads from media library have no context, or at least it is not trivial to find out a context. An upload of font file by itself do not mean that it is related in any way to your plugin, and even if you were detecting file types before changing the upload directories, it would still have a potential of ending in a mess.

  2. It is a big no-no to try to upload to anywhere except for the uploads directory. In a properly managed server, the web server is unlikely to have permissions to write to any other directory.

What you should do is either find out how to give a context to the upload (probably very hard or just impossible), or better, move the upload to a new directory only when you know it is associated with your settings. Assuming the file is uploaded and you use the attachment id in your form, move the file when the form is being submitted.

I also suggest to look at how EDD does it, and get inspiration.