Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Only users who have atleast one member type assigned can access BuddyPress Section
* Restrict access to BuddyPress to members having assigned member type.
function buddydev_protect_bp_from_non_members() {
// Do not restrict if
// Not BuddyPress, or Registration/Activation page or is site admin.
if ( ! is_buddypress() || bp_is_register_page() || bp_is_activation_page() || is_super_admin() ) {
// Change this to where you want to redirect the nin member user.
$non_member_redirect_page = site_url( '/' );
// Apply the Restriction.
// Check if the user is logged in and has a member type?
// If not, redirect to some page explaining that they need to be a member.
if ( ! is_user_logged_in() || ! bp_get_member_type( get_current_user_id() ) ) {
bp_core_redirect( $non_member_redirect_page );
add_action( 'bp_template_redirect', 'buddydev_protect_bp_from_non_members' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.