I'm trying to make a page where a user provides an ID of a attachment and the site will set the headers and deliver that file instead of a 404 page. so /download/1754 would lookup the attachment with that Id and output it for viewing/download depending on the file type.
I just can't think of a wordpress friendly way to do this from inside a plugin. I considered using add_rewrite_rule but couldn't see a good way around it, also considered checking $_SERVER['REQUEST_URI'] to deliver the content before any HTML but then I'd have to stop the page from rendering a 404 and I was not sure of a Wordpress friendly way to do this.
My current idea was to have my plugin make a download page, assign a template and have that template run the logic instead of my plugin class. while I have used this before for another situation it was very messy as I had to write a lot of code to force users to be unable to update or edit the file and recreate/delete it on activation.deactivation. so ideally I'd like to avoid that.
template_redirect
action - codex.wordpress.org/Plugin_API/Action_Reference/…. This action will allow you to check whatever you want, such as$_SERVER['REQUEST_URI']
, and if necessary redirect the user usingwp_safe_redirect()
. Have a bash, if you struggle update your questions with your results and we can help more :)wp_get_referer()
for that.