Hi there,
I need my BuddyDev PHP code that restricts access to all buddypress pages for non-logged in users to allow access for the listings page type ONLY:
for example:
and
So,
pages types that go from “https://taipeiexpats.com/members/ [ username] /listings/view/ ….
to be allowed by non-logged in users.
May you please help me alter this php code to allow such page types to achieve that?:
/** * Restrict access to BuddyPress for non logged users completely. */ function buddydev_restrict_bp_pages() { // If Logged in // Or not on BuddyPress pages // Or it is register/activation page // Do not restrict. if ( is_user_logged_in() || ! is_buddypress() || bp_is_register_page() || bp_is_activation_page() ) { return; } bp_core_redirect( wp_login_url() ); } add_action( 'bp_template_redirect', 'buddydev_restrict_bp_pages' );
Hello Kristian,
Thank you for posting. Try the following code for allow access to listing page for not loggedin users.
/** * Restrict access to BuddyPress for non logged users completely. */ function buddydev_restrict_bp_pages() { if ( ! is_buddypress() || bp_is_register_page() || bp_is_activation_page() ) { return; } if ( is_user_logged_in() ) { return; } elseif ( bp_is_current_component( 'listings' ) ) { // Replace by your component name if not works. return; } bp_core_redirect( wp_login_url() ); } add_action( 'bp_template_redirect', 'buddydev_restrict_bp_pages' );
Please let me know if works or not.
Regards
Ravi- This reply was modified 5 years, 3 months ago by Ravi.
THANK YOU!!
It actually works amazingly! 🙂
Ravi, I can’t thank you enough! Loving the BuddyDev products, and many of them are paid.
It’s an honor to be part of the BuddyDev community, sir.
Best,
Kristian
The topic ‘ [Resolved] Altering my buddydev php restrict code to only allow access to a page type’ is closed to new replies.