Find Answers and Get Support › Forums › Gwangi – PRO Multi-Purpose Membership, Social Network & BuddyPress Community Theme › Compatible Plugins › BuddyPress › Restrict not logged in users from accessing BuddyPress members contents
- This topic has 11 replies, 2 voices, and was last updated 6 years, 4 months ago by
Themosaurus.
-
AuthorPosts
-
alexParticipant@abourne
- 81 Topics
- 259 Posts
Do you have something like this available for your theme?
Restrict not logged in users from accessing BuddyPress or bbPress pages
November 1, 2018 at 04:59 #3177alexParticipant@abourne- 81 Topics
- 259 Posts
Perhaps this is a solution.
/** * 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 );
It seemingly works as I implemented it and nothing breaks…. but it excludes ALL BP components. I wish to REMAIN with the profile tiles ‘members directory’ page being visible and ONLY the actual profile views being hidden.
How to extend the code to do this function?
November 1, 2018 at 13:03 #3179alexParticipant@abourne- 81 Topics
- 259 Posts
Maybe this one? I tried and it broke my site, but many others have had success. Does it need any tweaks?
function my_private_profiles() { // Bail if not a profile page. if ( ! bp_is_user_profile() ) return; // Allow admin users. if ( current_user_can( 'manage_options' ) ) return; // Allow the profile owner. if ( bp_loggedin_user_id() == bp_displayed_user_id() ) return; // If we get to here, redirect to homepage. bp_core_redirect( home_url() ); } add_action( 'init', 'my_private_profiles' );
November 1, 2018 at 13:09 #3180alexParticipant@abourne- 81 Topics
- 259 Posts
Or something along these lines…?
function sh_walled_garden() { global $bp; if( bp_is_register_page() || bp_is_activation_page() ) return; if( ! bp_is_blog_page() && ! is_user_logged_in() ) bp_core_redirect( $bp->root_domain .'/'. 'LOGIN_PAGE_NAME' ); } add_action( 'get_header', 'sh_walled_garden' );
November 1, 2018 at 14:10 #3181@themosaurus- 1 Topics
- 1675 Posts
Hi @abourne,
Our theme is also compatible with Paid Memberships Pro, which is a WordPress plugin designed to restrict content for premium sites and to charge access in exchange for payments or subscription products:
You might also need an extra add-on plugin from PMP to restrict access to BuddyPress pages:
It should do the trick. ?
Regards,
November 1, 2018 at 15:51 #3189alexParticipant@abourne- 81 Topics
- 259 Posts
Thanks for the suggestions.
We are not a membership site so it is seemingly redundant for all that PMP provides.
Did install it and spent the last 70 mins customising it to fit our needs. It does EVERYTHING besides from the one thing I want – restrict bp profiles to be private only to registered/logged in members.
Plus, ‘member types’ cannot be registered during BP registration process…
How are users even supposed to streamline/flow via selecting a ‘member type’? Do they need to be directed to the members page specifically for this to happen.
Can we revert to my earlier request, in using a filter/function? Or do you have suggestions on how PMP can work for our needs?
November 1, 2018 at 19:42 #3202@themosaurus- 1 Topics
- 1675 Posts
Hi @abourne,
With the BuddyPress add-on, PMPRO can easily block access to member and group profiles
We think that working with a plugin such as PMPRO is a good solution because it has many nice and extensible features.
However I’ve found this PHP snippet :
/** * Redirect non logged-in users to registration page if they visit a profile page */ function gwangi_bp_logged_out_page_template_redirect() { if( ! is_user_logged_in() && bp_is_user() ) { wp_redirect( home_url( '/register/' ) ); exit(); } } add_action( 'template_redirect', 'gwangi_bp_logged_out_page_template_redirect' );
Regards,
November 2, 2018 at 12:34 #3231@themosaurus- 1 Topics
- 1675 Posts
Hi @abourne,
We’re not finding this specific option in the PMPro BuddyPress settings either. We share your concern; we find very odd to provide a plugin to restrict access throughout an entire social website except the profile pages… ?
Maybe, the PMPro support might be more helpful on that matter. If you wish to contact them, please visit the following page:However, the previously provided code snippet prevents any unregistered user to visit your member profile pages. They’ll be immediately redirected to your registration page.
/** * Redirect non logged-in users to registration page if they visit a profile page. */ function gwangi_custom_bp_logged_out_page_template_redirect() { if( ! is_user_logged_in() && bp_is_user() ) { wp_redirect( home_url( '/register/' ) ); exit(); } } add_action( 'template_redirect', 'gwangi_custom_bp_logged_out_page_template_redirect' );
Please note that you can edit this snippet and redirect to another page if you wish. Just change this
/register/
for your new page URL.PMPro remains useful for other specific tasks like preventing unregistered users to use the private messaging system or access premium blog posts.
Regards,
November 5, 2018 at 17:41 #3315@themosaurus- 1 Topics
- 1675 Posts
Great. Let’s hope they’ll change that in the future so we can remove this snippet. ?
In the meantime, it will do the trick.
Regards,
November 12, 2018 at 18:45 #3472 -
AuthorPosts
The topic ‘Restrict not logged in users from accessing BuddyPress members contents’ is closed to new replies.