Support only during business hours : Monday to friday, from 8:30 am – 5:30 pm CEST

Due to the decrease in our staff due to vacations, our response time may be longer.

Be sure we're doing our best to manage your topic as soon as possible.

Restrict not logged in users from accessing BuddyPress members contents

This topic is resolved
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    Do you have something like this available for your theme?

    Restrict not logged in users from accessing BuddyPress or bbPress pages

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    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?

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    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' );
    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    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' );
    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    This is the closest solution, but costs $29….

    BP Simple Private Pro

    Ideally prefer a function filter from the above.

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1676 Posts
    @themosaurus

    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:

    Paid Memberships Pro

    You might also need an extra add-on plugin from PMP to restrict access to BuddyPress pages:

    BuddyPress Integration

    It should do the trick. ?

    Regards,

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    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?

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1676 Posts
    @themosaurus

    Hi @abourne,

    With the BuddyPress add-on, PMPRO can easily block access to member and group profiles

    BuddyPress Integration

    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,

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    All I can see is the following screen, which does not provide the restriction required. Is there another component that you’re regarding, if not this one?

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1676 Posts
    @themosaurus

    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:

    Support

    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,

    alex
    Participant
    • 81 Topics
    • 259 Posts
    @abourne

    Thanks for sharing your insights. I do concur, it’s strange that profiles cannot be restricted using PMP. I used your snippet.

    Themosaurus
    Keymaster
    Themosaurus Support
    • 1 Topics
    • 1676 Posts
    @themosaurus

    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,

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Restrict not logged in users from accessing BuddyPress members contents’ is closed to new replies.

Troubleshooting Demo Imports

You're trying to setup your theme but you're experiencing errors when importing the demo content? Or you've just followed the setup guide but your website doesn't look exactly like our demo? These are common issues for which you can find easy and quick fixes.

Happy With our Support So Far?

Feel free to review our theme on Themeforest! It helps us making our products more known to new potential customers, which allow us more time to improve the quality and develop new features. #SharingIsCaring ❤️

Discover MatchPress

Skip • Like • Super-Like

Add powerful matching features like Member likes, skips, super likes, conditional private messaging and much more.