Skip to content

Conversation

@indigetal
Copy link

Summary
Ensure the Freemius Customer Portal initializes for anonymous (logged-out) visitors by registering/enqueuing the remote dashboard script with WordPress and declaring jquery as a dependency.

Problem

  • The shortcode previously emitted raw <script src="...dashboard.js"> and an inline initializer, while the plugin incorrectly called wp_enqueue_style('jquery'). Many themes do not load jQuery for anonymous users, which caused:
    • Uncaught ReferenceError: jQuery is not defined
    • Uncaught ReferenceError: FS is not defined
  • This made the embedded Customer Portal appear blank to logged-out visitors.

What I changed

  • Replaced raw script-tag output in the shortcode with proper WP enqueuing:
    • wp_enqueue_script( 'jquery' );
    • wp_enqueue_script( 'fs-members-dashboard', WP_FS__MEMBERS_DASHBOARD_SUBDOMAIN . '?ck=...', array( 'jquery' ), null, true );
    • Use wp_add_inline_script( 'fs-members-dashboard', 'FS.Members.configure(...).open();' ) to run the initializer after the remote script loads.
  • File modified: freemius-dashboard.php

Why this fix

  • Uses WordPress best-practices (script registration + dependencies) to guarantee correct load order and avoid relying on themes or other plugins to provide jquery.
  • Keeps remote script loading unchanged (still served from users.freemius.com) but prevents runtime errors when jquery is absent.

How to reproduce

  1. Install this plugin and add [fs_members store_id="..." public_key="..."] to a page.
  2. Visit the page while logged out.
  3. Without this patch: console shows jQuery is not defined and the portal is blank. With this patch: portal initializes and performs API calls.

Testing performed

  • Manual verification on a site: visited the shortcode page as a logged-out user; dashboard initialized and API calls completed successfully.
  • Linter check run on freemius-dashboard.php — no lint errors.

Notes

  • Fetch-based diagnostics may still show CORS warnings because dashboard.js does not include Access-Control-Allow-Origin, but loading by <script> tag (the usage method here) is unaffected.
  • If maintainers prefer a different approach (e.g., dynamically loading a bundled jQuery fallback), I can prepare an alternate patch.

Suggested labels

  • bug, patch, needs review

References

…alizer

  Summary
  - Register/enqueue `fs-members-dashboard` via `wp_enqueue_script()` with `jquery` as a dependency.
  - Use `wp_add_inline_script()` to run `FS.Members.configure(...).open()` after the remote script loads.
  - Remove raw <script src="..."> output from the shortcode.

  Why
  - Logged-out pages may not load jQuery by default; the previous implementation relied on jQuery being globally available and caused:
    - `Uncaught ReferenceError: jQuery is not defined`
    - `Uncaught ReferenceError: FS is not defined`
  - This caused the embedded Customer Portal to be blank for anonymous users.

  Files changed
  - `freemius-dashboard.php`

  Testing performed
  - Manual repro: visited page as a logged-out user after the change; dashboard initialized and performed API calls.
  - Diagnostic scripts and console logs available on request.

  Notes
  - The remote `dashboard.js` still loads from `users.freemius.com`; fetch-based diagnostics may show CORS warnings, but script-tag loading remains valid.
  - If maintainers prefer, I can provide an alternate fallback that dynamically injects a bundled jQuery only if missing, but the recommended approach is proper WP enqueueing.
…ugin name

Restored original plugin name and all references to “Customer Portal” that were altered when the repo was forked.

- Implemented a robust fix for the missing jQuery dependency by registering/enqueuing the remote `dashboard.js` via `wp_enqueue_script()` with `jquery` as a dependency and using `wp_add_inline_script()` to run the `FS.Members.configure(...).open()` initializer after the script loads.
- Rationale: anonymous (logged-out) pages did not reliably include jQuery, causing `Uncaught ReferenceError: jQuery is not defined` and preventing `FS` initialization. Enqueuing the script via WP ensures correct load order and follows WP best practices.

- Files changed:
  - `freemius-dashboard.php` — restored plugin header text and replaced raw `<script>` output with WP enqueue/inline script approach.

- Testing performed:
  - Manual verification as a logged-out user: dashboard initialized and performed API calls after the change.
  - Linter check run on the modified file — no errors.

- Notes:
  - The remote `dashboard.js` is still loaded from `users.freemius.com`; fetch-based diagnostics may show CORS warnings but script-tag execution remains valid.
  - If maintainers prefer a different approach (e.g., optional fallback jQuery bundle), I can prepare an alternate patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant