Skip to content

feat(elementor): add enrollment visibility controls to widgets#3191

Open
faisalahammad wants to merge 2 commits into
gocodebox:devfrom
faisalahammad:fix/3099-elementor-enrollment-visibility
Open

feat(elementor): add enrollment visibility controls to widgets#3191
faisalahammad wants to merge 2 commits into
gocodebox:devfrom
faisalahammad:fix/3099-elementor-enrollment-visibility

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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.php

Adds add_visibility_controls() which registers a new "Enrollment Visibility" section under the Advanced tab with two selects ("Display to" and "Enrolled In"). The render() method now evaluates those settings before delegating to a new abstract render_widget() method. Adds protected is_visible() and private check_enrollment() helpers that implement the same decision tree used by the blocks library. A new llms_elementor_widget_is_visible filter allows third-party customization of the visibility decision.

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-blocks package.

All six Elementor widget classes

Each widget's render() is renamed to render_widget() and now just contains the do_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 to add_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.yml

New hand-written changelog entry under the added type with minor significance.

Testing

  1. Install the plugin on a WordPress site with Elementor active.
  2. Open a course in Elementor, add a LifterLMS widget (Pricing Table, Course Progress, etc.), open the Advanced tab.
  3. Confirm the new "Enrollment Visibility" section shows "Display to" and "Enrolled In" controls.
  4. For each "Display to" value, 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.
  5. In the Elementor editor, change the widget to "enrolled users" and 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 dev unrelated to this change.

Screenshots

image

Types of changes

New feature (non-breaking change which adds functionality)

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.

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
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner June 16, 2026 16:03
@brianhogg brianhogg moved this to Awaiting Review in Development Jun 16, 2026
@brianhogg brianhogg added this to the 11.0 milestone Jul 21, 2026
Comment thread includes/elementor/class-llms-elementor-widget-course-meta-info.php
@brianhogg brianhogg moved this from Awaiting Review to Review in Progress in Development Jul 21, 2026
@brianhogg

brianhogg commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@faisalahammad Thanks for the PR! If we're going to add this in, we'd want it to match the current enrollment visibility functionality, specifically for when "enrolled users" or "non-enrolled users or visitors" is chosen and you can pick specific courses. Unless there's a limitation in Elementor in doing that?

CleanShot 2026-07-21 at 09 11 06@2x CleanShot 2026-07-21 at 09 13 51@2x

The first option is also "in this course".

@brianhogg brianhogg moved this from Review in Progress to To do in Development Jul 21, 2026
faisalahammad added a commit to faisalahammad/lifterlms that referenced this pull request Jul 21, 2026
…rols

- Replace @SInCE [version] placeholders with @SInCE 10.1.0
- Add apply_filters('llms_elementor_widget_is_visible') hook for extensibility
- Change render_widget() from abstract to concrete with empty default
- Refactor is_visible() to single filter return point

Addresses PR feedback.

Refs gocodebox#3191
…rols

- Add apply_filters('llms_elementor_widget_is_visible') hook for extensibility
- Change render_widget() from abstract to concrete with empty default
- Refactor is_visible() to single filter return point

Addresses PR feedback.

Refs gocodebox#3191
@faisalahammad
faisalahammad force-pushed the fix/3099-elementor-enrollment-visibility branch from d79574c to 21e363a Compare July 21, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

2 participants