Integrating with Membership Plugins

Seamlessly integrate with MemberPress, Restrict Content Pro, and Paid Memberships Pro.

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

FeatureMembership PluginAttributes 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

  1. Install and activate MemberPress
  2. Configure payment gateway
  3. Create membership levels
  4. Install Attributes User Access
  5. 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.

  1. Create custom login page with Attributes shortcode
  2. In MemberPress settings, set login URL to your custom page
  3. 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) {
        // There is no `attributes_is_2fa_verified()`, and nothing equivalent:
        // the second factor is verified during sign-in and leaves no queryable
        // state afterwards. What you can ask is whether the account has 2FA
        // ENROLLED, which is the useful gate for premium content.
        if (! get_user_meta($user->ID, 'attrua_2fa_enabled', true)) {
            wp_safe_redirect(home_url('/set-up-two-factor/'));
            exit;
        }
    }

    return $authorized;
}

Integration 2: Restrict Content Pro

Installation and Setup

  1. Install Restrict Content Pro (RCP)
  2. Configure subscription levels
  3. Install Attributes User Access
  4. 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 an RCP registration link under the Attributes login form.
// `attrua_after_login_form` is an ACTION: echo the markup, do not return it.
// There is no `attributes_login_form_footer` filter.
add_action('attrua_after_login_form', 'add_rcp_register_link');

function add_rcp_register_link() {
    $register_url = rcp_get_register_url();

    printf(
        '<p class="register-link"><a href="%s">%s</a></p>',
        esc_url($register_url),
        esc_html__('Create an Account', 'your-textdomain')
    );
}

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 className="unified-dashboard">
        <div className="dashboard-header">
            <h2>My Account Dashboard</h2>

        <div className="dashboard-grid">
            <!-- RCP Subscription Info -->
            <div className="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; ?>

            <!-- Attributes Security Status -->
            <div className="dashboard-widget">
                <h3>Security</h3>
                <?php if (get_user_meta($user_id, 'attrua_2fa_enabled', true)) : ?>
                    <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; ?>

    <?php
    return ob_get_clean();
}
add_shortcode('unified_dashboard', 'unified_member_dashboard');

Integration 3: Paid Memberships Pro

Installation Steps

  1. Install Paid Memberships Pro (PMPro)
  2. Configure membership levels
  3. Set up payment gateway
  4. Install Attributes
  5. 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 className="pmpro_checkout_security">
            <h3>Security Verification</h3>
            <p>For your security, business and enterprise accounts require two-factor authentication.</p>

            <?php if (!get_user_meta($user_id, 'attrua_2fa_enabled', true)) : ?>
                <p className="pmpro_error">
                    Please <a href="<?php echo home_url('/setup-2fa/'); ?>">enable two-factor authentication</a>
                    before completing this purchase.
                </p>
            <?php endif; ?>

        <?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 && !get_user_meta($user_id, 'attrua_2fa_enabled', true)) {
        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('attrua_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.

  • 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 CaseRecommended Setup
Simple Membership SiteMemberPress + Attributes (login/security)
Course PlatformRestrict Content Pro + Attributes + LearnDash
Community SitePMPro + Attributes + BuddyPress
Corporate IntranetAttributes only (no membership plugin needed)

Something missing or out of date? Tell support.