Skip to content

4.2.12 regression: close_buffer() at shutdown PHP_INT_MIN flushes other plugins' buffers, breaks Groovy Menu #1149

Closed

Description

@mr305fireball

Description

Since 4.2.12 (PR #1132, "process page HTML outside PHP's output-buffer display handler"), Groovy Menu's header menu no longer appears on the front end. Rolling back to 4.2.11 fixes it. So does adding add_filter( 'optml_capture_at_shutdown', '__return_false' ); on 4.2.12.

Cause: Groovy Menu's Divi auto-integration starts its own output buffer on init (priority 0). On shutdown (priority 0) it runs ob_get_clean() and inserts the menu HTML after <body>. In 4.2.12, Optml_Manager::close_buffer() is hooked to shutdown at PHP_INT_MIN (inc/manager.php:428) and flushes every buffer above Optimole's own:

while ( ob_get_level() > self::$ob_level ) { if ( ! @ob_end_flush() ) { break; } }

That flushes Groovy Menu's buffer before Groovy's shutdown callback runs. Groovy then gets Optimole's empty buffer, finds no <body>, and the fully generated menu HTML (~40 KB) is thrown away.

Expected: the Groovy Menu is inserted into the page, as it was on 4.2.11.
Actual: the menu markup is missing on every page. Only Groovy Menu's inline JS settings are printed.

Step-by-step reproduction instructions

  1. Install the Divi theme and Groovy Menu (premium) and enable Groovy Menu's auto-integration for Divi. Assign a menu to the "Groovy menu Primary" location.
  2. Install Optimole 4.2.12 (or 4.2.13), connect it, and leave image replacement enabled.
  3. Load any front-end page with page caching bypassed.
  4. The Groovy Menu markup (.gm-navbar, .gm-preset-id-* wrapper) is missing from the HTML.
  5. Roll back to Optimole 4.2.11, or add add_filter( 'optml_capture_at_shutdown', '__return_false' );, and reload: the menu appears.

Screenshots, screen recording, code snippet or Help Scout ticket

Buffer stack traced on an uncached render (PHP CLI, same page):

  • After the template finishes, ob_level=5:
    Optml_Manager::handle_buffer_fallback → default output handler (Groovy Menu) → SiteGround_Optimizer\Parser\Parser::run → hefo_callback → wp_finalize_template_enhancement_output_buffer
  • At shutdown priority -1, ob_level=1: only Optml_Manager::handle_buffer_fallback remains
  • Groovy's groovy_menu_final_output filter receives a string of length 0

Same render with optml_capture_at_shutdown → false: Groovy receives the full page (~188 KB) and the menu is inserted.

On a live site the menu disappeared the morning after the auto-update to 4.2.12. It came back after rolling back to 4.2.11.

Possible directions:

  • Run the flush/capture later in shutdown (after default-priority callbacks) instead of at PHP_INT_MIN.
  • If other buffers are still open above Optimole's, fall back to the pre-4.2.12 behaviour instead of force-flushing them.
  • At minimum, document optml_capture_at_shutdown as a supported compatibility switch.

Environment info

WordPress 7.1, PHP 8.2.33, Optimole 4.2.12/4.2.13 (last working: 4.2.11), Divi 4.27.7, Groovy Menu 2.6.5, WP Rocket 3.23.x, SiteGround Optimizer 7.8.x, Header and Footer 3.3.6

Is the issue you are reporting a regression

Yes, this is a regression.

Activity

  1. added
    bugThis label could be used to identify issues that are caused by a defect in the product.
    on Sep 14, 2026
  2. added
    regressionIssue represents a change in behavior from a previous version that is not intended or desired..
    on Sep 14, 2026
  3. added theissue type on Sep 14, 2026
  4. pirate-bot commented on Sep 15, 2026

    @pirate-bot
    Collaborator

    Another customer reported this via support.

    Groovy Menu markup disappears from front-end pages when Optimole 4.2.12 or 4.2.13 is active with the Divi theme. This regression stems from commit d6cc7b54 in inc/manager.php, which introduced shutdown-based output capture (Optml_Manager::close_buffer()) at PHP_INT_MIN. This flushes buffers stacked above Optimole's buffer before Groovy Menu's own shutdown callback can retrieve and transform its buffer, leaving it empty. To reproduce, install Divi and Groovy Menu with auto-integration enabled, activate Optimole 4.2.12 or 4.2.13, and inspect an uncached front-end page where the menu wrapper will be missing (unlike v4.2.11).


    Source: HelpScout #3451076687
    Generated by bug-report-triage (ID: bug-report-triage_6aa88a9e391790.05456871)

  5. selul commented on Sep 15, 2026

    @selul
    Contributor

    Thanks for the detailed report. I reproduced this on 4.2.13 and can confirm the regression, the rollback, and the optml_capture_at_shutdown workaround.

    How I tested: Groovy Menu's auto-integration hooks ob_start() on init (priority 0) and ob_get_clean() on shutdown (priority 0), then inserts the menu after <body>. I mirrored that in a small mu-plugin and fetched the front end uncached:

    Scenario Menu inserted Buffer Groovy received
    4.2.11 yes full page
    4.2.13, Groovy buffer below Optimole's (init 0 start order) no 0 bytes
    4.2.13, Groovy buffer above Optimole's (order from your trace) no 0 bytes
    4.2.13 + optml_capture_at_shutdown → false yes full page

    Two notes on the analysis, since they affect the fix:

    1. The flush loop is only part of it. When Groovy's buffer sits below ours (the natural order with an init 0 start, since we open ours on template_redirect), the loop never touches it. What loses the menu there is the re-armed empty buffer: we capture and echo the page, then open a fresh buffer, and Groovy's ob_get_clean() grabs that empty one. Your trace shows our buffer at the bottom, so Groovy 2.6.5 may start later than the version I read, but both orderings break the same way.
    2. "Fall back to the pre-4.2.12 behaviour when other buffers are open above ours" isn't viable: on WordPress 7.1 core's own template-enhancement buffer is always above ours, so that fallback would trigger on every request. Moving the capture later in shutdown also can't go past priority 1, where core's wp_ob_end_flush_all() would flush our buffer through the pass-through handler and skip optimization.

    Fix: we're adding a Groovy Menu compatibility that takes over its shutdown step. Groovy's own shutdown callback is unhooked and its groovy_menu_final_output filter is applied to the page we capture, before image replacement, so the menu is inserted regardless of buffer order and its images get optimized too. PR incoming.

  6. self-assigned this
    on Sep 15, 2026
  7. selul commented on Sep 15, 2026

    @selul
    Contributor

    Fix is up in #1150 (targets development).

    Until the next release ships, you can install the fixed build directly: download the plugin ZIP from the PR build, then go to WP Admin → Plugins → Add New → Upload Plugin, upload it, and choose Replace current with uploaded when prompted. Your settings and connection are kept.

  8. rodica-andronache commented on Sep 15, 2026

    @rodica-andronache

    🤖 Automated QA Repro Steps

    Since Optimole 4.2.12, sites running the Divi theme with Groovy Menu's auto-integration lose their header menu entirely on the front end — the menu markup never makes it into the page, only Groovy Menu's inline settings script does. It affects every front-end page, and rolling back to 4.2.11 brings the menu back.

    Requires: Divi theme + Groovy Menu (premium) on a site where page caching can be bypassed.

    Reproduce on Optimole 4.2.13:

    1. Go to Groovy Menu → Integration and turn on auto-integration for Divi.
    2. Go to Appearance → Menus → Manage Locations and assign a menu to Groovy menu Primary.
    3. Go to Media → Optimole → Settings → General and make sure Image replacement is on, with Optimole connected.
    4. Load any front-end page with page caching bypassed, then view the page source and search for gm-navbar.
    • Bug: there is no gm-navbar element and no header menu on screen; only Groovy Menu's inline JS settings are present.
    • Fixed: the header menu renders, gm-navbar is present exactly once, and the menu's logo/images are served from the Optimole CDN domain.
    Edge cases
    • Add a Code Snippet with add_filter( 'optml_capture_at_shutdown', '__return_false' ); and reload — the menu must still appear exactly once (this path already worked before the fix and must not regress).
    • Groovy Menu active but auto-integration off, menu placed manually — menu renders normally, and no second copy appears.
    • Other themes with Optimole active and no Groovy Menu — pages render unchanged and images are still optimized.
    • Same page with WP Rocket and/or SiteGround Optimizer optimizations enabled — menu present once, page markup not truncated or duplicated.
    • Front-end page loaded while logged out vs. logged in as admin — menu present in both, no duplicate insertion.

    Fix: #1150 (open)

  9. pirate-bot commented on Sep 17, 2026

    @pirate-bot
    Collaborator

    QA agent — The Groovy buffer fix works in the matching public path; the proprietary Divi matrix remains unverified.

    The candidate restored one visible Groovy menu and optimized its fixture images in Groovy Menu 1.4.5's matching init/shutdown buffer path, while the same fixture lost the menu on qa-base. Legacy capture mode, manual placement, and both logged-in and logged-out views also kept exactly one menu, and all five added unit tests passed. The exact Divi, Groovy Menu premium, WP Rocket, and SiteGround Optimizer combinations could not be assembled from available packages, so those product-specific journeys still need human QA.

    Please still try

    1. Try Divi 4.27.7 with Groovy Menu premium 2.6.5 and its real auto-integration package; those proprietary components were unavailable.
    2. Try the full WP Rocket 3.23.x and SiteGround Optimizer 7.8.x compatibility matrix with Divi and Groovy Menu premium.
    3. Verify a front-end page on another theme with Groovy Menu deactivated and confirm ordinary images remain optimized; this explicit edge case was omitted from the immutable browser plan.
    4. Connect a real Optimole customer account and confirm the generated menu-image CDN URL delivers the optimized binary; this run used seeded connected state and inspected generated URLs.
    Lab notes (6 passed · 2 blocked)
    • ✅ With Groovy Menu free 1.4.5 exercising the reported init/shutdown output-buffer integration, the assigned auto-integrated menu is visible exactly once and both
    • ✅ With optml_capture_at_shutdown disabled through the documented legacy filter, the same Groovy Menu page still renders one and only one .gm-navbar menu.
    • ✅ With Groovy Menu auto-integration disabled and the menu placed manually via its shortcode, the manual page renders exactly one .gm-navbar and no automatic secon
    • ✅ A logged-out visitor loading the uncached auto-integration fixture sees exactly one Groovy menu with no duplicate insertion.
    • ✅ A logged-in administrator loading the uncached auto-integration fixture sees exactly one Groovy menu with no duplicate insertion.
    • ✅ The PR's added Test_Groovy_Menu test group completes successfully, covering both buffer orders, legacy mode, early flush behavior, compatibility loading, single
    • ⏸️ With Divi 4.27.7 and Groovy Menu premium 2.6.5 auto-integration enabled, the assigned Groovy primary menu renders on the uncached front end exactly once and its
    • ⏸️ With WP Rocket and SiteGround Optimizer output optimizations enabled alongside the reported Divi and Groovy premium setup, the page contains one menu and its ma

    Candidate codeinwp/optimole-wp b16784d; qa-base ac2459f. WordPress 7.1, PHP 8.2.33 for CLI and PHP-FPM, MariaDB 11.8.6, nginx, Twenty Twenty-Five 1.5. Installed built Optimole ZIP 4.2.13 and Groovy Menu free 1.4.5. Prepared an assigned gm_primary menu, real Groovy auto-integration, an uploaded PNG, auto and manual pages, and a query-scoped test mu-plugin for the documented legacy switch/manual-option states. Optimole connection and image replacement were seeded through Optml_Settings with a local test CDN key; this verifies URL replacement behavior, not a real customer account or live CDN delivery. PHPUnit 9.6.22 used the WordPress 7.1.0 test library.

    Run qa-agent_6aac02a6eea017.46174008.

    Full report, evidence and session trail

  10. added a commit that references this issue on Sep 18, 2026
    97661ed
  11. pirate-bot commented on Sep 21, 2026

    @pirate-bot
    Collaborator

    🎉 This issue has been resolved in version 4.2.14 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

  12. added
    releasedIndicate that an issue has been resolved and released in a particular version of the product.
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugThis label could be used to identify issues that are caused by a defect in the product.regressionIssue represents a change in behavior from a previous version that is not intended or desired..releasedIndicate that an issue has been resolved and released in a particular version of the product.

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions