feat(providers): add MemberPressMembershipProvider (v1.5.0) - #14
Merged
Merged
Conversation
Gates resources by one or more MemberPress memberships. Options are sourced from the memberpressproduct CPT via get_posts() and labels from post_title (synthetic "Membership #N" fallback). Access is granted when MeprUser::active_product_subscriptions() intersects any selected membership ID — subscription IDs are coerced to strings for a strict intersect against the stored option list. The provider depends on MemberPress. Every method guards its API calls behind is_available() (defined(MEPR_VERSION) && class_exists(MeprUser)), so when MemberPress is inactive: - The REST /providers payload reports available: false — ProviderDropdown hides the entry automatically. - get_options() short-circuits to [] (get_posts is never called). - user_has_access() denies (MeprUser is never instantiated). Files: - src/MemberPressMembershipProvider.php — new provider class with two filters (wpb_access_control_mepr_membership_options, wpb_access_control_mepr_membership_has_access). - src/AccessControlManager.php — registered as a default provider. - js/components/RoleOptionsPanel.js — description string for mepr_membership; existing checkbox panel renders the new options. - tests/Unit/MemberPressMembershipProviderTest.php — 20 new tests covering identity, is_available, get_options (unavailability guard, post→option mapping, title fallback, missing-ID skip, filter override) and user_has_access (unavailability guard, empty options, no subscriptions, intersect match, int→string coercion, filter override). - tests/bootstrap.php — adds MEPR_VERSION constant and a minimal global \MeprUser stub class so the test suite can run without MemberPress installed. - README.md / CHANGELOG.md — documented new provider and filters. PHPUnit: 158 tests / 216 assertions all green. JS assets rebuilt via wp-scripts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
mepr_membership), so the React UI's Who can access dropdown can gate a resource by one or more MemberPress membershipsmemberpressproductCPT viaget_posts()(canonical IDs/titles) — no MemberPress autoloader trip is required for the listingMeprUser::active_product_subscriptions()intersects any selected membership ID (IDs coerced to strings for the strict intersect)wpb_access_control_mepr_membership_optionsandwpb_access_control_mepr_membership_has_accessMemberPress-inactive safety
Every code path guards behind
is_available()(defined('MEPR_VERSION') && class_exists('MeprUser')). When MemberPress is inactive:/providerspayload reportsavailable: false→ the ReactProviderDropdownhides the entry automaticallyget_options()short-circuits to[]—get_posts()is never calleduser_has_access()denies —MeprUseris never instantiatedChanges
src/MemberPressMembershipProvider.php— new provider classsrc/AccessControlManager.php— registered alongsidewp_role/wp_user/wp_capability/bb_profile_typejs/components/RoleOptionsPanel.js— UI subtitle formepr_membershiptests/Unit/MemberPressMembershipProviderTest.php— 20 new teststests/bootstrap.php— minimal\MeprUserstub +MEPR_VERSIONso tests run without MemberPress installedassets/build/index.js— rebuilt viawp-scripts buildREADME.md/CHANGELOG.md— documentedTest plan
composer test— 158 tests / 216 assertions, all greennpm run build— wp-scripts compiles cleanly/providersreportsavailable: false, existingmepr_membershiprules deny🤖 Generated with Claude Code