Fix: enqueue dashboard.js with jquery dependency and inline initializer #13
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.
Summary
Ensure the Freemius Customer Portal initializes for anonymous (logged-out) visitors by registering/enqueuing the remote dashboard script with WordPress and declaring
jqueryas a dependency.Problem
<script src="...dashboard.js">and an inline initializer, while the plugin incorrectly calledwp_enqueue_style('jquery'). Many themes do not load jQuery for anonymous users, which caused:Uncaught ReferenceError: jQuery is not definedUncaught ReferenceError: FS is not definedWhat I changed
wp_enqueue_script( 'jquery' );wp_enqueue_script( 'fs-members-dashboard', WP_FS__MEMBERS_DASHBOARD_SUBDOMAIN . '?ck=...', array( 'jquery' ), null, true );wp_add_inline_script( 'fs-members-dashboard', 'FS.Members.configure(...).open();' )to run the initializer after the remote script loads.freemius-dashboard.phpWhy this fix
jquery.users.freemius.com) but prevents runtime errors whenjqueryis absent.How to reproduce
[fs_members store_id="..." public_key="..."]to a page.jQuery is not definedand the portal is blank. With this patch: portal initializes and performs API calls.Testing performed
freemius-dashboard.php— no lint errors.Notes
dashboard.jsdoes not includeAccess-Control-Allow-Origin, but loading by<script>tag (the usage method here) is unaffected.Suggested labels
bug,patch,needs reviewReferences
https://github.com/Freemius/freemius-users-dashboard(Customer Portal blank for logged-out users - jQuery is not defined)