Avoided setting the llms-tracking cookie when there are no events to track#2331
Merged
Conversation
Merged
brianhogg
pushed a commit
that referenced
this pull request
Jun 22, 2026
…age views stay cacheable (#3211) * Defer session cookie until session data is written LifterLMS emitted the wp_llms_session_<COOKIEHASH> cookie on the first page view of every anonymous visitor, even on pages that never touch the session. Full-page caches won't store responses carrying a Set-Cookie header, so this disabled anonymous page caching site-wide whenever LifterLMS was active. Make the session cookie lazy: a brand-new session lives in memory only (no Set-Cookie, no DB row) until the first write via LLMS_Session::set(), at which point the cookie is emitted. Anonymous visitors who never write session data never receive the cookie, so those responses stay cache-eligible. Mirrors the llms-tracking cookie approach from #2330 / #2331. Fixes #3210 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Emit the deferred session cookie unconditionally on first write The headers_sent() guard around the deferred set_cookie() call dropped the cookie whenever output had already started, which broke the new behavior under PHPUnit (and would have failed in CI). The eager cookie was previously emitted from the constructor with no such guard, and every first-party session write runs before output, so emit unconditionally to match that behavior and keep it testable. Seed a cookie in the existing-cookie session tests that previously relied on the constructor eagerly creating one. Verified locally: tests-run --group sessions,coupons -> 65 tests, 452 assertions, OK. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2330
Going to set the
llms-trackingcooking as soon as an events needs to be tracked.How has this been tested?
manually with the Advanced Videos add-on.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: