Snippet: make BuddyPress private, restrict members directory and profiles to members only

Are you looking for a little plugin to make your BuddyPress private, and restrict your social network to members only? If yes, this snippet is for you.

With this function, the non logged user who tries to access to BuddyPress social network (members directory or profile) is redirect to the BuddyPress registration.

function sqr_prevent_search_guest_user() {
if ( class_exists( 'BuddyPress' ) ) {
if (!is_user_logged_in() && (bp_is_directory() || bp_is_user())) {
wp_redirect(home_url() . '/register/');
exit;
}
}
}
add_action('template_redirect', 'sqr_prevent_search_guest_user');

The good news is that this snippet is WPML-friendly, so your French users will be redirect to the French version of the register page, etc…

Do not hesitate to use My Custom Functions plugin to insert this code in your BuddyPress install directly via your WordPress dashboard!

Don't miss business advice by email

No spam, just an email when new content is published.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

WordPress is the content management system of choice for online website builders. About 30% of the internet platforms currently available online are built around this system which has the share https://buff.ly/4gTcUuk

🫘 Flageolet beans, white beans, lentils, broad beans, chickpeas and other legumes are the best “slow carbohydrates” for health.
👉 Discover the superpowers of legumes in their dedicated content on Blooness: https://buff.ly/4b4nnlc

🍞 Sourdough bread with ancient flours is a more digestible alternative to traditional bread.
Natural fermentation can improve digestion and nutrient bioavailability.
👉 Learn more about the best breads at http://blooness.com

Load more

Don't miss business advice by email

No spam, just an email when new content is published.

en_USEN