Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug in output buffering for infinite scroll #17050

Open
arnowelzel opened this issue Sep 2, 2020 · 0 comments
Open

Possible bug in output buffering for infinite scroll #17050

arnowelzel opened this issue Sep 2, 2020 · 0 comments
Labels
[Feature] Infinite Scroll Good For Community [Pri] Low [Type] Bug When a feature is broken and / or not performing as intended

Comments

@arnowelzel
Copy link

Also see arnowelzel/lightbox-photoswipe#45 about this.

See the following code fragment:

if ( have_posts() ) {
// Fire wp_head to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer.
ob_start();
wp_head();
while ( ob_get_length() ) {
ob_end_clean();
}

What this does:

  1. Start a new output buffer
  2. Call wp_head()
  3. As long as there is anything in the output buffer (and only then!) delete the buffer and stop buffering

However this causes a lot of problems if wp_head() does not create any output (which might happen in rare cases). Also note that ob_end_clean() only needs to be called once - after calling this, there is no buffer any longer (also see https://www.php.net/manual/en/function.ob-end-clean.php). On the other hand it also must be called every time after using ob_start() and not only if there is anything in the buffer.

My plugin "Lightbox with PhotoSwipe" won't work at least on one site using infinite scroll and the fix by the user was to add ob_end_clean() after the while()-loop. The correct code should be:

 if ( have_posts() ) { 
 	// Fire wp_head to ensure that all necessary scripts are enqueued. Output isn't used, but scripts are extracted in self::action_wp_footer. 
 	ob_start(); 
 	wp_head(); 
 	ob_end_clean(); 
@arnowelzel arnowelzel changed the title Possible bug in output buffering Possible bug in output buffering for infinite scroll Sep 2, 2020
@jeherve jeherve added [Pri] Low [Type] Bug When a feature is broken and / or not performing as intended [Feature] Infinite Scroll Good For Community labels Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Infinite Scroll Good For Community [Pri] Low [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

No branches or pull requests

2 participants