fix(assets): only enqueue context-specific assets on LifterLMS pages - #3263
Open
faisalahammad wants to merge 1 commit into
Open
fix(assets): only enqueue context-specific assets on LifterLMS pages#3263faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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-sliderwebui-popover(script and style)llms-ajaxllms-form-checkout(narrowed to account and checkout only)The
lifterlms-stylesstylesheet and thellmsscript remain enqueued by default for backward compatibility, but both can be suppressed through the newllms_load_frontend_assetsfilter.Adds the
llms_load_frontend_assetsfilter 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-enqueuelifterlms-stylesso they remain styled when the filter is forced off. The pricing table shortcode also self-enqueueswebui-popoverso 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:llms-form-checkoutenqueued on account and checkout pages.llms_load_frontend_assetsfilter forces load on a plain page.llms_load_frontend_assetsfilter suppresses gated assets on an LLMS page.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:
[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
llms_load_frontend_assetsfilter.Checklist: