Post ID: 1054
Title: Integrating with Membership Plugins
Slug: integrating-membership-plugins
Publication Date: 2024-12-25
Author: Admin
Status: Published
Comment Status: Open
Excerpt: Seamlessly integrate with MemberPress, Restrict Content Pro, and Paid Memberships Pro.
Category
- Primary: Tutorials (7)
Tags
- Tutorials (137)
- Integration (145)
- Membership (146)
- Plugins (147)
Overview
Combine Attributes User Access with popular membership plugins to leverage the strengths of each system. This tutorial covers integration strategies, configuration steps, and best practices for MemberPress, Restrict Content Pro, and Paid Memberships Pro.
Integration Strategy
| Feature | Membership Plugin | Attributes Plugin |
|---|---|---|
| Payments & Subscriptions | ✓ Primary | — |
| Content Restrictions | ✓ Primary | ✓ Enhanced |
| Login Customization | — | ✓ Primary |
| Security Features (2FA) | — | ✓ Primary |
| Role Management | ✓ Basic | ✓ Enhanced |
| User Dashboards | ✓ Basic | ✓ Enhanced |
Recommended Division of Responsibilities
- Membership Plugin: Handles payments, subscriptions, and pricing
- Attributes: Handles login pages, security, and advanced access control
Integration 1: MemberPress
Installation Order
- Install and activate MemberPress
- Configure payment gateway
- Create membership levels
- Install Attributes User Access
- Configure integration
Role Synchronization
Map MemberPress membership levels to WordPress roles for use with Attributes.
/**
* Sync MemberPress membership to WordPress role
*/
add_action('mepr-account-is-active', 'sync_memberpress_to_role', 10, 2);
function sync_memberpress_to_role($event) {
$user_id = $event->user()->ID;
$membership = $event->product();
// Map MemberPress membership IDs to WordPress roles
$role_map = array(
123 => 'basic_member', // Basic Membership ID
124 => 'premium_member', // Premium Membership ID
125 => 'vip_member' // VIP Membership ID
);
// Remove old membership roles
$user = get_userdata($user_id);
foreach ($role_map as $role) {
$user->remove_role($role);
}
// Add new role
if (isset($role_map[$membership->ID])) {
$user->add_role($role_map[$membership->ID]);
}
}
/**
* Remove role when membership expires
*/
add_action('mepr-account-is-inactive', 'remove_memberpress_role', 10, 2);
function remove_memberpress_role($event) {
$user_id = $event->user()->ID;
$membership = $event->product();
$role_map = array(
123 => 'basic_member',
124 => 'premium_member',
125 => 'vip_member'
);
if (isset($role_map[$membership->ID])) {
$user = get_userdata($user_id);
$user->remove_role($role_map[$membership->ID]);
}
}
Login Page Configuration
Use Attributes for custom login page while MemberPress handles account management.
- Create custom login page with Attributes shortcode
- In MemberPress settings, set login URL to your custom page
- Configure redirects based on membership level
Content Restriction Coordination
/**
* Enhance MemberPress restrictions with Attributes
* Use MemberPress for course/content access
* Use Attributes for page-level security (IP, 2FA)
*/
// Example: Require 2FA for premium content
add_filter('mepr_is_authorized', 'require_2fa_for_premium', 10, 4);
function require_2fa_for_premium($authorized, $user, $post, $membership) {
// Premium membership ID
if ($membership->ID == 124) {
// Check if 2FA is verified
if (!attributes_is_2fa_verified($user->ID)) {
// Redirect to 2FA verification
wp_redirect(home_url('/verify-2fa/'));
exit;
}
}
return $authorized;
}
Integration 2: Restrict Content Pro
Installation and Setup
- Install Restrict Content Pro (RCP)
- Configure subscription levels
- Install Attributes User Access
- Configure role mappings
Subscription Level to Role Mapping
/**
* Map RCP subscription levels to roles
*/
add_action('rcp_set_status', 'rcp_sync_role', 10, 4);
function rcp_sync_role($member_id, $status, $old_status, $membership_id) {
$customer = rcp_get_customer_by_user_id($member_id);
if (!$customer) {
return;
}
$user = get_userdata($member_id);
// Get active membership
$membership = rcp_get_membership($membership_id);
$subscription_id = $membership->get_object_id();
// Role mapping
$role_map = array(
1 => 'free_member', // Free subscription
2 => 'bronze_member', // Bronze subscription
3 => 'silver_member', // Silver subscription
4 => 'gold_member' // Gold subscription
);
// Remove all membership roles
foreach ($role_map as $role) {
$user->remove_role($role);
}
// Add appropriate role if active
if ($status === 'active' && isset($role_map[$subscription_id])) {
$user->add_role($role_map[$subscription_id]);
}
}
Registration Form Integration
/**
* Use Attributes login page with RCP registration
*/
// Add RCP registration link to Attributes login form
add_filter('attributes_login_form_footer', 'add_rcp_register_link');
function add_rcp_register_link($footer_html) {
$register_url = rcp_get_register_url();
$footer_html .= '<p class="register-link">';
$footer_html .= '<a href="' . esc_url($register_url) . '">';
$footer_html .= 'Create an Account</a>';
$footer_html .= '</p>';
return $footer_html;
}
Unified Member Dashboard
/**
* Create unified dashboard combining RCP and Attributes
*/
// Dashboard shortcode
function unified_member_dashboard() {
if (!is_user_logged_in()) {
return 'Please log in to view your dashboard.';
}
$user_id = get_current_user_id();
$customer = rcp_get_customer_by_user_id($user_id);
ob_start();
?>
<div class="unified-dashboard">
<div class="dashboard-header">
<h2>My Account Dashboard</h2>
</div>
<div class="dashboard-grid">
<!-- RCP Subscription Info -->
<div class="dashboard-widget">
<h3>Subscription</h3>
<?php if ($customer && $customer->is_active()) : ?>
<p>Status: <strong>Active</strong></p>
<p>Level: <?php echo $customer->get_membership_level_name(); ?></p>
<p>Expires: <?php echo $customer->get_expiration_date(); ?></p>
<a href="<?php echo rcp_get_account_page_url(); ?>">Manage Subscription</a>
<?php else : ?>
<p>No active subscription</p>
<a href="<?php echo rcp_get_register_url(); ?>">View Plans</a>
<?php endif; ?>
</div>
<!-- Attributes Security Status -->
<div class="dashboard-widget">
<h3>Security</h3>
<?php if (attributes_is_2fa_enabled($user_id)) : ?>
<p>Two-Factor Auth: <strong>Enabled</strong></p>
<?php else : ?>
<p>Two-Factor Auth: <strong>Disabled</strong></p>
<a href="<?php echo home_url('/setup-2fa/'); ?>">Enable 2FA</a>
<?php endif; ?>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode('unified_dashboard', 'unified_member_dashboard');
Integration 3: Paid Memberships Pro
Installation Steps
- Install Paid Memberships Pro (PMPro)
- Configure membership levels
- Set up payment gateway
- Install Attributes
- Configure integration
Membership Level to Role Sync
/**
* Sync PMPro levels with WordPress roles
*/
add_action('pmpro_after_change_membership_level', 'pmpro_sync_role', 10, 2);
function pmpro_sync_role($level_id, $user_id) {
$user = get_userdata($user_id);
if (!$user) {
return;
}
// Role mapping
$role_map = array(
1 => 'starter_member',
2 => 'pro_member',
3 => 'business_member',
4 => 'enterprise_member'
);
// Remove all membership roles
foreach ($role_map as $role) {
$user->remove_role($role);
}
// Add new role (level_id = 0 means cancelled)
if ($level_id > 0 && isset($role_map[$level_id])) {
$user->add_role($role_map[$level_id]);
}
}
Checkout Page Security
/**
* Add security verification during PMPro checkout
*/
add_action('pmpro_checkout_before_submit_button', 'add_checkout_security');
function add_checkout_security() {
$user_id = get_current_user_id();
// For high-value memberships, require additional verification
$level_id = intval($_REQUEST['level']);
if ($level_id >= 3) { // Business or Enterprise
?>
<div class="pmpro_checkout_security">
<h3>Security Verification</h3>
<p>For your security, business and enterprise accounts require two-factor authentication.</p>
<?php if (!attributes_is_2fa_enabled($user_id)) : ?>
<p class="pmpro_error">
Please <a href="<?php echo home_url('/setup-2fa/'); ?>">enable two-factor authentication</a>
before completing this purchase.
</p>
<?php endif; ?>
</div>
<?php
}
}
/**
* Prevent checkout without 2FA for high-tier levels
*/
add_filter('pmpro_registration_checks', 'require_2fa_for_business');
function require_2fa_for_business($continue) {
$level_id = intval($_REQUEST['level']);
$user_id = get_current_user_id();
if ($level_id >= 3 && !attributes_is_2fa_enabled($user_id)) {
pmpro_setMessage('Two-factor authentication is required for business and enterprise memberships.', 'pmpro_error');
return false;
}
return $continue;
}
Common Integration Scenarios
Scenario 1: Custom Login with Membership Payments
- Use Attributes for: Login page design, 2FA, session management
- Use Membership Plugin for: Pricing, payments, subscriptions
Scenario 2: Enhanced Content Protection
- Use Membership Plugin for: Access level determination
- Use Attributes for: IP restrictions, device limits, time-based access
Scenario 3: Unified User Experience
- Create custom dashboard: Combine subscription info from membership plugin with security settings from Attributes
- Single login system: Use Attributes login page for all authentication
Troubleshooting Common Issues
Issue: Role Conflicts
Problem: User has multiple roles and access is inconsistent.
Solution:
// Ensure membership roles take priority
function cleanup_conflicting_roles($user_id) {
$user = get_userdata($user_id);
$membership_roles = array('basic_member', 'premium_member', 'vip_member');
// User should only have one membership role
$user_roles = array_intersect($user->roles, $membership_roles);
if (count($user_roles) > 1) {
// Remove all but the highest level
foreach ($user_roles as $role) {
$user->remove_role($role);
}
// Re-add the correct one based on active subscription
}
}
Issue: Redirect Conflicts
Problem: Both plugins trying to redirect after login.
Solution: Use Attributes redirect with higher priority:
// Override membership plugin redirect
add_filter('attributes_login_redirect', 'override_membership_redirect', 999, 3);
function override_membership_redirect($redirect_to, $user_id, $user) {
// Remove other redirect filters
remove_all_filters('login_redirect', 10);
// Apply your logic
return $redirect_to;
}
Issue: Login Form Conflicts
Problem: Multiple login forms causing confusion.
Solution: Disable membership plugin login forms, use only Attributes.
Integration Testing Checklist
- Test new member registration
- Verify role assignment after purchase
- Test content access for each level
- Verify subscription cancellation removes access
- Test upgrade/downgrade scenarios
- Verify payment processing works
- Test login/logout functionality
- Verify redirects work correctly
- Check dashboard displays correct info
Best Practices
- Clear Separation: Define which plugin handles which features
- Consistent Roles: Maintain one-to-one mapping between membership levels and roles
- Test Thoroughly: Test all subscription lifecycle events
- Document Integration: Keep notes on customizations for future updates
- Update Carefully: Test updates in staging before production
- Monitor Performance: Multiple plugins can impact performance; optimize queries
Recommended Plugin Combinations
| Use Case | Recommended Setup |
|---|---|
| Simple Membership Site | MemberPress + Attributes (login/security) |
| Course Platform | Restrict Content Pro + Attributes + LearnDash |
| Community Site | PMPro + Attributes + BuddyPress |
| Corporate Intranet | Attributes only (no membership plugin needed) |