Hi!
I’m using WooCommerce Memberships with Member Types Pro.
Users on my site have the member type ‘Member’ assigned to them when they subscribe via WooCommerce.
What I’d like to do is hide Buddypress from logged in users who do not have a Member Type assigned to them – these will typically be users who have an expired membership and have reverted to the WooCommerce role of ‘Customer.
Is there a way that this can be done, either based on the user’s role, or lack of a Member Type?
Many thanks!
Hi Gavin,
Thank you for the topic.Yes, It is doable with a few lines of code.
Can you please help me understand how do you perceive hiding BuddyPress? What features do we restrict fro the user?
Please let me know the features we need to restrict(example:- do not allow access to profile) and I will assist.
Thank you
BrajeshThanks Brajesh.
The aim is to prevent access to:
– activity stream
– member list
– user profilesI’ve been able to hide the menu items for the relevant users, but the pages are still directly accessible via the URL due to the limitations of woocommerce memberships.
Hi Gavin,
Thank you.Please use the following code.
// Check access for user. add_action( 'bp_template_redirect', function () { if ( ! is_user_logged_in() || is_super_admin() ) { return; } // User has somemeber type? if ( bp_get_member_type( bp_loggedin_user_id() ) ) { return; } // redirect as user does not ahve any member type. $redirect_to = site_url( '/' ); //change with where you want to redirect. Make sure it is outside buddypress. if ( is_buddypress() ) { // if we are in BuddyPress section, redirect. bp_core_redirect( $redirect_to ); } } );
It redirects user to site home page if they try to access any BuddyPress content.
Regards
Brajesh
The topic ‘ [Resolved] Restrict access to Buddypress if no member type’ is closed to new replies.