• Resolved jmslbam

    (@jmslbam)


    Servus Arno,

    I encoutered a weird bug and would like to pick you brain. It started when I had set WP_DEBUG to false. When on true, it doesnt occur. It is an combination of my stack which uses Twig via https://github.com/level-level/Clarkson-Core/

    I have selected Version 5 btw as settings, while with version 4 this behaviour doesn’t occur.

    I disabled all plugins and enabled them to find the cullprit and this plugin trigger a White Screen of Death.

    So I tracked it to a combination of “bufferStart” and “outputFooter” methods. Disabling the “bufferStart” fixed it, but looking at the content I had a feeling that a ob_start without an “ob_end_flush” ever being called.

    And there in the outputFooter I saw the check if not version 4 then just return void.
    When I added a “ob_end_flush();” before that return it started working again.

    I think it’s an combination of the way the Twig rendering is implemented, on “template_include in combination an exit().

    So I understand that without the whole Clarkson / Twig rendering flow this bug would not occur, but am I correct that calling an “ob_end_flush” makes the code a bit more predictable compated to when you really on the “auto flush” of PHP when it finishes a loading a page?

    I solved it myself by adding and “ob_end_flush” on the wp_footer action, but let me know if you consider fixing it in the plugin yourself.

    Have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Arno Welzel

    (@awelzel)

    Thanks for pointing this out. Output buffer issues are sometimes hard to track down – but so far I never had an issue with PhotoSwipe 5, also see here:

    https://wordpress-demo.arnowelzel.de/lightbox-with-photoswipe-5/

    https://wordpress-demo.arnowelzel.de/lightbox-with-photoswipe-5-overlay-caption/

    However, while examinig outputFooter() I realized, that for PhotoSwipe 5 the method will not only suppress the output for the PhotoSwipe 4 specific frontend code – but it will also not run the output buffer flush if needed. While this works in most cases due to the fact, that PHP will flush the buffer anyway, it can cause issues if other plugins or the theme don’t handle the output buffer correctly.

    Version 5.8.2 contains a fix for this. If that version still does not work for you, you may have to check if any of the other plugins you use may also have output buffer issues. Just calling ob_end_flush() without any additional checks is also not correct, since this may flush the output buffer of another plugin or theme which did not close it properly. My plugin does not always call ob_start(), but only if it was not disabled for the current page/post or by a filter hook.

    Plugin Author Arno Welzel

    (@awelzel)

    Oh – and another important thing:

    Using Twig along with Composer and the generated autoloader by Composer in WordPress is usually also a bad idea, since you may end up with multiple autoloaders which can create a conflict with each other.

    I tried using Twig for the backend in my plugin as well and very soon I removed that again, when I realized how many problems it causes due to the requirement of an autoloader for Twig. Your experiences may vary, but I would not recommend using Composer for any code in WordPress if you can not fully control every aspect of your WordPress installation including all plugins and theme(s). As soon as there is more than one plugin using Composer you will get serious issues at some point.

    To see how to use Composer, see projects like RoundCube or any Symfony or Laravel based project since Composer was originally designed for Symfony and is also used by Laravel.

    Thread Starter jmslbam

    (@jmslbam)

    The fix worked, danke!

    And yes, I’m aware of the possible issues that can occure with Composer in combination with other plugins that require same packages. Fortunatly Twig has not been a source of issues for the past 10.5 years that I have incorparated it in the front-end of WordPress sites.

    And yes, myself as freelancer and while I worked at the agencies, we have had full control over all installed plugins in a Bedrock kinds of setup.

    And I’m also aware of PHP Scoper or Mozart kind of solutions that would prevent issues you describe, although Clarkson Core is not being maintained anymore and I’m also stepping over to Timber. They indeed could incorparate such a custom namespaced Twig instead of loading it directly, but yeah.

    Thank you for the heads-up and the quick fix!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.