Skip to content

fix(assets): only enqueue context-specific assets on LifterLMS pages - #3263

Open
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/146-conditional-frontend-assets
Open

fix(assets): only enqueue context-specific assets on LifterLMS pages#3263
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/146-conditional-frontend-assets

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Description

LifterLMS currently enqueues a set of frontend scripts and styles on every page where the plugin is active, even plain posts and pages that contain no LifterLMS content. This change conditionally enqueues the context-specific assets so they only load on LifterLMS-related pages (course, lesson, membership, account, checkout).

Affected assets (now gated):

  • jquery-ui-tooltip, jquery-ui-datepicker, jquery-ui-slider
  • webui-popover (script and style)
  • llms-ajax
  • llms-form-checkout (narrowed to account and checkout only)

The lifterlms-styles stylesheet and the llms script remain enqueued by default for backward compatibility, but both can be suppressed through the new llms_load_frontend_assets filter.

Adds the llms_load_frontend_assets filter for sites that want to force assets on or off:

  • add_filter( 'llms_load_frontend_assets', '__return_true' ); forces a load on pages the auto-detection misses (e.g. a custom template embedding LifterLMS shortcodes).
  • add_filter( 'llms_load_frontend_assets', '__return_false' ); fully suppresses frontend assets for non-LifterLMS templates.

Shortcodes that render LifterLMS UI off the auto-detected page types ([lifterlms_courses], [lifterlms_memberships], [lifterlms_pricing_table], [lifterlms_checkout]) now self-enqueue lifterlms-styles so they remain styled when the filter is forced off. The pricing table shortcode also self-enqueues webui-popover so locked-plan popovers continue to work.

Fixes #146

How has this been tested?

Unit tests cover all gating paths in tests/phpunit/unit-tests/class-llms-test-frontend-assets.php:

  • Context assets not enqueued on a plain (non-LifterLMS) page.
  • Context assets enqueued on a single course page.
  • llms-form-checkout enqueued on account and checkout pages.
  • llms_load_frontend_assets filter forces load on a plain page.
  • llms_load_frontend_assets filter suppresses gated assets on an LLMS page.
  • Core assets (lifterlms-styles, llms) stay always-on by default.

Test run: composer tests -- --filter LLMS_Test_Frontend_Assets (19/19 pass).
Coding standards: composer check-cs (clean).

Manual testing covered:

  • Plain page, course page, account page, checkout page source-viewed to confirm expected assets are present or absent.
  • [lifterlms_pricing_table] on a plain page with a locked access plan: popover displays on click.
  • [lifterlms_courses] on a plain page: course loop is styled.
  • [lifterlms_checkout] shortcode on a page other than the configured checkout: form-checkout script loads.

Environment: WordPress 6.x, PHP 7.4/8.x.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality) - the llms_load_frontend_assets filter.

Checklist:

  • This PR requires and contains at least one changelog file.
  • My code has been tested.
  • My code passes all existing automated tests.
  • My code follows the LifterLMS Coding & Documentation Standards.

Conditionally enqueue the frontend scripts and styles that are only used
on LifterLMS-related pages (course, lesson, membership, account,
checkout) instead of on every page where LifterLMS is active.

Affected assets:
- jquery-ui-tooltip, jquery-ui-datepicker, jquery-ui-slider
- webui-popover (script + style)
- llms-ajax
- llms-form-checkout (now only on account/checkout)

Adds the llms_load_frontend_assets filter as an escape hatch to force
load (or fully suppress) frontend assets. Core assets (lifterlms-styles
and llms) stay enqueued by default for backward compatibility with
shortcodes that render on any page; the filter can suppress them.

Shortcodes that render LifterLMS UI off the auto-detected page types
([lifterlms_courses], [lifterlms_memberships], [lifterlms_pricing_table],
[lifterlms_checkout]) now self-enqueue lifterlms-styles so they remain
styled when the filter is forced off.

Fixes gocodebox#146
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner July 22, 2026 11:15
@brianhogg brianhogg moved this to Awaiting Review in Development Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting Review

Development

Successfully merging this pull request may close these issues.

2 participants