I have a plugin that hooks into “wp_handle_upload” filter. Within that scope I’d like to be able to identify where the upload came from, meaning I want to treat it differently if it was uploaded from within a post vs. the media library vs. a plugin/theme settings page (for example the header image for a template).
The only thing passed into my function is an array with file,url,type. Is there a way to identify where it came from?
I could probably create an exception and examine the stack trace, is that a decent solution? If so, what might I be looking for in the stack?
Thanks!
I was able to figure it out by looking at the form parameters, which I don’t really like doing since it’s not part of the wordpress api. if anybody has a better idea, please leave a comment.
It seems to be reliable for posts and library, but the “other” is probably not 100% reliable since plugins and themes could add parameters to trick the code into thinking it was one of the other types.