Skip to content

Add llms_can_user_bypass_restrictions filter for custom role bypass - #3271

Open
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/2180-custom-role-bypass-filter
Open

Add llms_can_user_bypass_restrictions filter for custom role bypass#3271
faisalahammad wants to merge 1 commit into
gocodebox:devfrom
faisalahammad:fix/2180-custom-role-bypass-filter

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Description

Add the llms_can_user_bypass_restrictions filter to llms_can_user_bypass_restrictions() so custom and third-party roles (e.g. Memberium, User Role Editor) added to Unrestricted Preview Access can bypass enrollment, drip, and prerequisite restrictions.

The edit_post capability gate added in #1987 blocks roles that lack that capability. The filter gives developers an opt-in escape hatch. Default null preserves the existing behavior, including the #1974 security fix.

$can_bypass = apply_filters( 'llms_can_user_bypass_restrictions', null, $user, $post_id );
if ( null !== $can_bypass ) {
    return (bool) $can_bypass;
}

Fixes #2180

How has this been tested?

  • composer tests -- --filter=test_llms_can_user_bypass_restrictions passes (29 assertions across 3 methods including 2 new filter tests).
  • composer check-cs clean.
  • Manual test plan in TESTING_INSTRUCTIONS.md.

Environment: LifterLMS dev environment, WordPress 6.x, PHP 7.4+.

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.

Custom and third-party roles (e.g. Memberium, User Role Editor) added to
Unrestricted Preview Access could not bypass enrollment, drip, and
prerequisite restrictions because the edit_post capability gate blocks
roles lacking that cap.

Adds a pre_ short-circuit filter at the top of
llms_can_user_bypass_restrictions() so developers can opt custom roles
in. Default null preserves existing behavior. Returns boolean to
override all internal checks.

Fixes gocodebox#2180
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner July 24, 2026 05:02
@brianhogg brianhogg moved this to Awaiting Review in Development Jul 24, 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