WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 4 months ago

#43172 closed defect (bug) (invalid)

Output Buffering and <pre>

Reported by: briansahagun Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.2
Component: General Keywords: reporter-feedback close
Focuses: Cc:

Description

It seems like output buffering removes the formatting of the contents of <pre> tags.

ob_start();
the_content();
$content_of_the_content = ob_get_contents();
ob_end_clean();

Change History (7)

#1 follow-up: @dd32
4 months ago

  • Keywords reporter-feedback close added

Hi @briansahagun,

Can you please provide an example of what you expected, and what you got instead?

Assuming the code given is running as-is, there's nothing in WordPress that I'm aware of that could be modifying it's behaviour, and it's likely a quirk of the processing code.

#2 in reply to: ↑ 1 ; follow-up: @briansahagun
4 months ago

Hi @dd32, I copy and pasted a CSS code inside the <pre> tag.

In the Visual/Text editor, everything seems ok. But when I publish it and view it using my theme (wherein I run the_content() inside ob_start() ), the formatting is removed.

Please see images: https://www.flickr.com/gp/briansahagun/NWX0J1 https://www.flickr.com/gp/briansahagun/798R62

But when I switch to Twentyseventeen theme, the formatting is preserved.

I already tested putting the_content() outside OB and it works fine–so I thought it must be the OB.

Thanks.

Replying to dd32:

Hi @briansahagun,

Can you please provide an example of what you expected, and what you got instead?

Assuming the code given is running as-is, there's nothing in WordPress that I'm aware of that could be modifying it's behaviour, and it's likely a quirk of the processing code.

#3 in reply to: ↑ 2 ; follow-up: @SergeyBiryukov
4 months ago

Replying to briansahagun:

In the Visual/Text editor, everything seems ok. But when I publish it and view it using my theme (wherein I run the_content() inside ob_start() ), the formatting is removed.

Please see images: https://www.flickr.com/gp/briansahagun/NWX0J1 https://www.flickr.com/gp/briansahagun/798R62

But when I switch to Twentyseventeen theme, the formatting is preserved.

The second link shows a 403 error. If output buffering works as expected in Twenty Seventeen but not in your theme, it sounds like the issue is somewhere in your theme rather than in WordPress core. Could you track it down further?

#4 in reply to: ↑ 3 @briansahagun
4 months ago

The second link shows that even in the HTML source, the content of <pre> has no formatting.

Twenty Seventeen does not have any OB–what I meant to say is that I switched theme to ensure that the same content is ok without OB (as seen in Twenty Seventeen theme).

I already tried putting the_content() outside OB (using my theme) and <pre> works as expected.

But when put inside OB, the formatting gets discarded.

Here it is: https://flic.kr/p/22xoLgD

The first CSS is the_content() outside OB. The second CSS is within OB.

Replying to SergeyBiryukov:

Replying to briansahagun:

In the Visual/Text editor, everything seems ok. But when I publish it and view it using my theme (wherein I run the_content() inside ob_start() ), the formatting is removed.

Please see images: https://www.flickr.com/gp/briansahagun/NWX0J1 https://www.flickr.com/gp/briansahagun/798R62

But when I switch to Twentyseventeen theme, the formatting is preserved.

The second link shows a 403 error. If output buffering works as expected in Twenty Seventeen but not in your theme, it sounds like the issue is somewhere in your theme rather than in WordPress core. Could you track it down further?

#5 follow-up: @dd32
4 months ago

This doesn't appear to be a WordPress issue from what's presented here.

It sounds like perhaps there's a plugin or other code in play which is affecting output buffers on your install. You might like to try it on a different server environment and/or look into what `ob_list_handlers` reports to see if something is indeed filtering buffers. Trying all plugins disabled and trying your code in the default theme may also help narrow it down.

You may also want to use ob_get_clean() instead of calling ob_get_contents()/ob_end_clean() individually too.

#6 in reply to: ↑ 5 @briansahagun
4 months ago

You're right, I tried OB in Twenty Seventeen and it didn't remove the formatting of <pre>.

Replying to dd32:

This doesn't appear to be a WordPress issue from what's presented here.

It sounds like perhaps there's a plugin or other code in play which is affecting output buffers on your install. You might like to try it on a different server environment and/or look into what `ob_list_handlers` reports to see if something is indeed filtering buffers. Trying all plugins disabled and trying your code in the default theme may also help narrow it down.

You may also want to use ob_get_clean() instead of calling ob_get_contents()/ob_end_clean() individually too.

#7 @johnbillion
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.