WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#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)

#1 @swissspidy
2 years ago

  • Keywords close added

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 calls wp_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 using die() to stop further output.

#2 @jdgregson
2 years ago

  • Resolution set to invalid
  • Status changed from new to closed

@swissspidy
My apologies, your comment made me dig a little deeper and I determined that this was caused by another plugin (NextGEN Gallery).

#3 @SergeyBiryukov
2 years ago

  • Component changed from General to Themes
  • Focuses template added
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.