BuddyPress: Members-Only Community Pages
Sends logged-out visitors who open BuddyPress pages (members, profiles, activity, groups) to the login screen, so the community is visible to members only.
Opens WPIDE on
Code
if ( ! function_exists( 'buddypress' ) ) {
return;
}
add_action( 'template_redirect', function () {
if ( is_user_logged_in() || ! is_buddypress() ) {
return;
}
if ( bp_is_register_page() || bp_is_activation_page() ) {
return;
}
wp_safe_redirect( wp_login_url( home_url( add_query_arg( array() ) ) ) );
exit;
} );
Notes
Registration and account activation pages stay open so new members can still sign up.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.