Improved: Updated JS snippet to make sure it's skipped by JS optimization plugins#289
Improved: Updated JS snippet to make sure it's skipped by JS optimization plugins#289
Conversation
…not optimized by optimization plugins which respect this attribute, i.e., WP Rocket and WP-Optimize.
📝 WalkthroughWalkthroughThe pull request modifies script registration and compatibility handling. The Assets class now registers the Plausible analytics script with a proper JS source URL instead of an empty source, streamlines the enqueue call, and adjusts the bootstrap logic. The Compatibility class adds a filter hook for minification exclusion and introduces a new method to append optimization-related attributes to the script tag. Changes
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Assets.php`:
- Around line 44-47: Update the outdated docblock above the wp_register_script
call: replace the "dummy script" wording with a brief, accurate description that
this registers the Plausible analytics script with an actual URL (via
$this->get_js_url(true)) under the handle 'plausible-analytics' and respects the
plausible_load_js_in_footer filter for footer loading; reference the
wp_register_script invocation and the get_js_url(true) usage so future readers
understand this is a real external script registration, not a placeholder.
In `@src/Compatibility.php`:
- Line 271: Replace all uses of str_contains (e.g., str_contains($url,
$rest_endpoint)) with a PHP 7.2-compatible check using strpos !== false inside
the Compatibility class (or wherever those calls appear), e.g., change to
(strpos($url, $rest_endpoint) !== false); alternatively, if you decide to
require PHP 8.0+, update the plugin's declared minimum PHP version instead of
changing code—pick one approach and apply it consistently across all occurrences
of str_contains.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 15deff52-bbbe-4714-82b3-d02e991c13a9
📒 Files selected for processing (2)
src/Assets.phpsrc/Compatibility.php
Summary by CodeRabbit
New Features
Bug Fixes
Documentation