- Restrict Access to Your Entire Website
- Using the Centralized Rules System in SureMembers
- Restrict a Particular Content on a Page
- Manually Add or Remove Users from Memberships
- Yearly Membership Plan using SureCart and SureMembers
- How to set up Login Restrictions
- Menu Item Visibility
- Redirect Users at Login or Logout
- Secure Digital Downloads
- Download and Access Your License
- Activate or Deactivate Your License
- SureCart and SureMembers Affiliate Program
- Pricing Plan Changes
- Show or Hide Inline Content Using SureMembers Shortcodes
- How to Use SureMembers’ Restrict this Block Setting?
- How to Integrate SureCart with SureMembers
- How to Integrate with WooCommerce For Paid Memberships
- Use SureMembers to Protect Your SureDash Courses and Content
- How to Set Up Unauthorized Access Rules for Users
How to Add or Remove Users from Memberships
We’ve introduced two new functions in SureMembers to give you more control when managing user access. You can now add or remove users from Membership using the code below.
These functions are helpful if you want to handle access dynamically, like after a user registers, completes a purchase, or performs a specific action on your site.
suremembers_add_user_to_group( $user_id, $access_group_id );
This function adds a user to one or more memberships.
Example:
add_action( 'admin_footer', function() {
suremembers_add_user_to_group( 12, 145 );
// This adds user ID 12 to Membership ID 145
});
To add the user to multiple Memberships:
add_action( 'admin_footer', function() {
suremembers_add_user_to_group( 12, [145, 146, 147] );
});
suremembers_remove_user_from_group( $user_id, $access_group_id );
This function removes a user from one or more Memberships.
Example:
add_action( 'admin_footer', function() {
suremembers_remove_user_from_group( 12, 145 );
// This removes user ID 12 from Membership ID 145
});
To remove the user from multiple Memberships:
add_action( 'admin_footer', function() {
suremembers_remove_user_from_group( 12, [145, 146, 147] );
});
Note:
- In the examples above, we’re using the
admin_footeraction hook just for demonstration. - You should replace it with an action hook that matches when you want this to happen. For example:
- After a user completes a form
- After a WooCommerce order is marked complete
- On user login/logout
- Make sure your code is added in a custom plugin or a child theme’s
functions.php.
If you’re unsure which hook to use, feel free to contact support or check WordPress documentation for action hooks related to your use case.
We don't respond to the article feedback, we use it to improve our support content.