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!

Ziyad Bachalany

L’auteur

Ziyad Bachalany

Entrepreneur et consultant web à Paris. J’ai dirigé un groupe de quatre restaurants, lancé un logiciel pour restaurateurs et publié des extensions WordPress. Je construis des sites, des outils et des automatisations pour les indépendants, les commerces et les PME.

Commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *