Tulip Media

Entrepreneurial thoughts

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!

 

My latest tweets

New shorts on Blooness 👉 Vitality, longevity, weight loss: the ultimate guide to proteins in the keto-Mediterranean diet is online on Blooness. https://buff.ly/3xxNvpj
https://buff.ly/4cG2GM4

New shorts on Blooness 👉 The new premium content comes out in 48 hours, and what content! This will be the most comprehensive guide on the amount of protein to consume on a keto-Mediterranean diet. See you soon !
https://buff.ly/3L2KbFP

New Post: Combo, the best solution to put an end to the headache of scheduling and HR management https://buff.ly/4eE6JtT

Load more

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 *

en_USEN