Make BuddyPress Pages Members Only
Do you want to make the BuddyPress section of your site member only? It's pretty easy.
All we need to do is check if a user is not logged in and they are in BuddyPress section and the current page is not Register or activation page, redirect them to login.
Here is the code.
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Force non logged in users */ function buddydev_members_only_bp_page() { if ( ! is_user_logged_in() && is_buddypress() && ! ( bp_is_register_page() || bp_is_activation_page() ) ) { $redirect = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; bp_core_redirect( wp_login_url( $redirect ) ); } } add_action( 'bp_template_redirect', 'buddydev_members_only_bp_page' ); |
You can put the code in your bp-custom.php or your theme's functions.php
Feel free to customise it as you please.
Happy Networking!
Hi Brajesh,
This doesn't work.
Thanks
Hi Brajesh,
I got it to work but too restrictive had to with a plugin for better control.
Thanks
Hi Edward,
Thank you for confirming that it is working.
Yes, It restricts whole BuddyPress section except the register/activation page. I am glad you found a plugin that serves the purpose.
It is feasible to skip some parts by using other conditional such as bp_is_user() , bp_is_group() etc.
Regards
Brajesh
Thank you Brajesh for the always free tips and tricks for BuddyPress. Great job.
Thank you for the kind words Thomas.