#43116 closed defect (bug) (invalid)
wp_footer actions being applied to output when the Content-Type header is set to "application/pdf"
Reported by: | jdgregson | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9.2 |
Component: | Themes | Keywords: | close |
Focuses: | template | Cc: |
Description
We encountered an issue trying to download some PDFs through index.php using Gravity Forms. I believe this issue should be fixed in WordPress Core rather than the Gravity Forms plugin.
When a PDF downloaded through index.php contains a </body> tag (which is valid inside XFA forms in the PDF), WordPress sees the tag and inserts the code which was added to the wp_footer hook, completely breaking the PDF.
I have downloaded the PDF using wget and can see that the "Content-Type" header is set to "application/pdf".
I suggest that the wp_footer hook (and probably all hooks) check to see if the Content-Type is something other than the default "text/html" and avoid executing if so.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Hey there,
Welcome to WordPress Trac!
How exactly are you creating that PDF download?
WordPress doesn't execute the
wp_footer
call simply because it sees</body>
somewhere. That hook is only called when a theme callswp_footer()
in their template.Thus, when you return some special content like a PDF with a different content type., you need to bypass the regular theme output by using filters like
template_include
or by usingdie()
to stop further output.