-
Notifications
You must be signed in to change notification settings - Fork 34
Fixed: add missing $in_footer parameter to wp_enqueue/register_script calls #308
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
56e2552
fix: add missing $in_footer parameter to wp_enqueue/register_script c…
masteradhoc 054cee7
move to args
masteradhoc f572a37
add args
masteradhoc fe8f08e
add args
masteradhoc 833bffa
Merge pull request #303 from masteradhoc/notinfooter
Dan0sz 28ac914
Pass tests when code coverage uploading fails.
Dan0sz 0cc6432
Fix test.
Dan0sz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,3 +91,4 @@ jobs: | |
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| slug: plausible/wordpress | ||
| continue-on-error: true | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cross-file root cause: Two integration scripts force the main analytics script to footer.
Both
plausible-affiliate-links(src/Assets.php line 43) andplausible-form-submit-integration(src/Integrations/FormSubmit.php lines 61-62) declare'plausible-analytics'as a dependency and setin_footer => true. WordPress dependency resolution moves the parent'plausible-analytics'script to the footer when any dependent child is marked for footer placement.This creates a timing hazard: the main script at
src/Assets.php:104defaults to header placement via the filterplausible_load_js_in_footer(defaultfalse), and several inline event handlers at lines 77, 172, and 204 registerDOMContentLoadedlisteners. When scripts execute in the footer (after DOM parsing),DOMContentLoadedhas already fired, so these listeners never run.Recommended fix: Either (1) keep integration scripts in the header to preserve current behavior, or (2) replace
DOMContentLoadedlisteners with immediate execution guards or alternative ready-state checks that work when scripts load after DOM is ready.🤖 Prompt for AI Agents
🧩 Analysis chain
🏁 Script executed:
Repository: plausible/wordpress
Length of output: 1028
Fix integration test to assert
wp_footeroutput forin_footerenqueued affiliate links script.src/Assets.phpenqueuesplausible-affiliate-linkswith['in_footer' => true], buttests/integration/AssetsTest.phponly callsdo_action( 'wp_head' )and asserts the output containsplausible-affiliate-links.js(andconst plausibleAffiliateLinks). Within_footer => true, the script should be emitted duringwp_footer, so update the test to trigger/capturedo_action( 'wp_footer' )(or adjust the assertions to match the new placement).🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're wrong there. Maybe that has changed in recent WP versions, but it's perfectly possible now to enqueue dependend script in the footer while the parent script remains in head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
WordPress wp_enqueue_script in_footer dependency resolution: can a child script be in footer while parent script remains in header? WordPress version changeLength of output: 18679
@Dan0sz, you're absolutely right, and I apologize for the incorrect analysis. My understanding of WordPress dependency resolution was backwards.WordPress promotes dependencies upward (from footer → header) to ensure they load before the script that depends on them — not downward. So when
plausible-affiliate-links(child,in_footer => true) listsplausible-analyticsas a dependency, WordPress leavesplausible-analyticsin the header where it was registered and simply emits the child script in the footer afterward. The parent loads first (in<head>), the child loads later (in footer) — perfectly valid ordering.My concern about
DOMContentLoadedlisteners breaking was also unfounded: those inline scripts are attached toplausible-analyticswhich remains in the header and fires normally.Would you like me to resolve my two comments on this PR since they were based on an incorrect assumption?
✏️ Learnings added
🧠 Learnings used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please. You were right about the test breaking, though. It should be fixed in #0cc6432.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, something went wrong! Please try again later. 🐰 💔