Tagged: buddypress
First, thank you for amazing work!
I would like to add an exclusion to not redirect for specific pages, being the “About Us” “FAQs” And “Contact” pages. Is there any simple way to add this to the code you provided in your Blog? The code that I used that solved my privacy issue for my Buddypress site is this:
/**
* Make a WordPress site Private, works with/Without BuddyPress
*
* @author sbrajesh
* @global string $pagenow
*
*/
function buddydev_private_site() {//do not restrict logged in users
if ( is_user_logged_in() ) {
return ;
}
//first exclude the wp-login.php
//register
//activate
global $pagenow;//if we are here, the user is not logged in, so let us check for exclusion
//we selectively exclude pages from the list//are we on login page?
if ( $pagenow == ‘wp-login.php’ ) {
return ;
}//let us exclude the home page
if ( is_front_page() ) {
return ;
}//handle Special case of BuddyPress registration/Login
if ( function_exists( ‘is_buddypress’ ) && is_buddypress() ) {if ( bp_is_activation_page() || bp_is_register_page() ) {
return ;
}
}$redirect_url = wp_login_url( site_url(‘/’) );//get login url,
wp_safe_redirect( $redirect_url );
exit( 0 );
}add_action( ‘template_redirect’, ‘buddydev_private_site’, 0 );
Hey Ravi,
Thank you for your response. The blog post I am referencing is the following:
https://buddydev.com/making-a-wordpress-buddypress-site-private-the-right-way/
I am trying to add a few more exceptions to specific pages. Is there an easy way for me to accomplish this?
Thanks again for all your hard work!
Hello Lance,
Please confirm. Are you referring to the following blog?
https://buddydev.com/making-a-wordpress-buddypress-site-private-the-right-way/Please take a look at the following plugin:
https://wordpress.org/plugins/buddypress-members-only/Regards
RaviHey Ravi,
I tried using that plugin, but it does not seem to work on my site. I then came across that blog post and used that code snippet and it worked like a charm. I just couldn’t seem to find a way to exclude the three other pages I was hoping could be accessed. Any suggestions?
Thanks,
LanceHello Lance,
Please try the following code and change exclude page ids with yours. Please let me know it helps you or not.
/** * Make a WordPress site Private, works with/Without BuddyPress * * @author sbrajesh * @global string $pagenow * */ function buddydev_private_site() { // Do not restrict logged in users. if ( is_user_logged_in() ) { return; } global $pagenow; // Are we on login page or site front page? if ( $pagenow == 'wp-login.php' || is_front_page() ) { return; } // Change page ids with yours. $exclude_page_ids = array( 7, 8 ); if ( is_page( $exclude_page_ids ) ) { return; } // Handle Special case of BuddyPress registration/Login. if ( function_exists( 'is_buddypress' ) && is_buddypress() ) { if ( bp_is_activation_page() || bp_is_register_page() ) { return; } } // Get login page url. $redirect_url = wp_login_url( site_url( '/' ) ); wp_safe_redirect( $redirect_url ); exit( 0 ); } add_action( 'template_redirect', 'buddydev_private_site', 0 );
Regards
Ravi
You must be logged in to reply to this topic.