feat(elementor): add enrollment visibility controls to widgets#3191
Open
faisalahammad wants to merge 1 commit into
Open
feat(elementor): add enrollment visibility controls to widgets#3191faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
Add an Enrollment Visibility section to every LifterLMS Elementor widget. Course authors can now show or hide a widget based on the current visitor's enrollment status, login state, or enrollment in specific courses or memberships, mirroring the visibility option available on standard Gutenberg blocks. A server-side render gate in the widget base class evaluates the visibility attributes against the current user. Inside the Elementor editor the widget always renders so authors can keep editing it regardless of their own enrollment status. Fixes gocodebox#3099
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.
Summary
Adds an Enrollment Visibility section to every LifterLMS Elementor widget. Course authors can now show or hide a widget based on the current visitor's enrollment status, login state, or enrollment in specific courses or memberships, mirroring the visibility option that already exists on standard Gutenberg blocks.
The decision is evaluated server-side in the widget base class. Inside the Elementor editor the widget always renders so authors can keep editing it regardless of their own enrollment status.
Fixes #3099
Changes
includes/elementor/class-llms-elementor-widget-base.phpAdds
add_visibility_controls()which registers a newEnrollment Visibilitysection under the Advanced tab with two selects (Display toandEnrolled In). Therender()method now evaluates those settings before delegating to a new abstractrender_widget()method. Adds private helpersis_visible()andcheck_enrollment()that implement the same decision tree used by the blocks library.Before: every widget rendered unconditionally.
After: a widget renders only when the current visitor passes the configured visibility check.
Why: keeps the decision logic in one place inside the widget layer so the change does not depend on edits to the vendored
libraries/lifterlms-blockspackage.All six Elementor widget classes
Each widget's
render()is renamed torender_widget()and now just contains thedo_shortcode()call. Each widget's_register_controls()ends with$this->add_visibility_controls()so the new section is added automatically.Before:
protected function render() { echo do_shortcode( '...' ); }After:
protected function render_widget() { echo do_shortcode( '...' ); }plus a call toadd_visibility_controls()at the end of_register_controls().Why: the base class now controls the visibility gate, subclasses only define what to render.
.changelogs/3099-elementor-enrollment-visibility.ymlNew hand-written changelog entry under the
addedtype withminorsignificance.Testing
lifterlms-fix-3099.zipon a WordPress site with Elementor active.Enrollment Visibilitysection showsDisplay toandEnrolled Incontrols.Display tovalue, save the page and verify the front end:everyone— visible to all visitors.enrolled users+in this course— visible only when the visitor is enrolled in the current course.enrolled users+in any course or membership— visible when the visitor has any enrollment.non-enrolled users or visitors— hidden from enrolled users.logged in users/logged out users— visible only to the matching audience.enrolled usersand confirm it still appears in the editor preview regardless of your own enrollment status.Result: works as expected. PHPCS clean, PHPUnit suite passes aside from two pre-existing failures on
devunrelated to this change.Screenshots