BuddyBoss Home – Web Support Forums General BuddyPress (general issues) Making a template visible only to logged in users

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Question

    #33411
    @haime

    Hi,

    Allow me to be the first to ask a question here.

    I have a plugin (WP Idea Stream) which is great and works with BuddyBoss. The only thing is I want no public access to the ideas, only for logged in users.

    I implemented a copy of page.php (and called it ideastream.php) as per the developer instructions and now I want to make the template logged-in only accessible. I have been struggeling with this a couple of days now (and posted to the developer as well as to wordpress forum in order to find a solution.

    I have this code (that does not work) and would like to know if someone in the BuddyBoss community has a working code?

    <?php
    /**
     * Template Name: Idea Stream
     *
     * @package WordPress
     * @subpackage BuddyBoss
     * @since BuddyBoss 3.0
     */
    get_header(); ?>
    
    	<div id="primary" class="site-content">
    	
    		<div id="content" role="main">
    
    <?php if (!is_user_logged_in()) {
       echo 'Welcome, registered user!';
    } else {
    			while ( have_posts() ) : the_post(); {
    				get_template_part( 'content', 'page' );
    				comments_template( '', true ); }
    			endwhile; // end of the loop.
    	    }			
    endif; //end of if-loop. ?>
    
    		</div><!-- #content -->
    		
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Thnaks a lot in advance!

    Answers

    #33429

    Anonymous
    @

    You’re using !is_user_logged_in.

    The ! means “not”. So you’re saying, if IS NOT user logged in…

    Remove that exclamation mark, and then it will be saying, if IS user logged in, which is what I believe you want.

    #33440
    @haime

    @michael the wording is not correct. I do mean to have !is_user_logged_in 🙂

    I do mean something like this:

    <?php if (!is_user_logged_in()) {
       echo 'no access';
    }

    The problem is that the template code above generates a blank screen, both for not-logged-in as well as for logged-in 🙁

    regards!

    #33449
    @style960

    @haime Do this have to be done by template? Can you not achieve with a private URL and a logged-in only menu link?

    #33508
    @haime

    @style960 I did think about that, but I want to have real privacy, also from robots (and not only the ones that respect robots.txt). Unfortunately WP Idea Stream uses rewrite based on page-template and not a real page (e.g. with a shortcode.)

    #33560
    @cfcommunity

    I think you could use a conditional to check if the page is an “idea steam”. I quickly took a look at the code and found a bunch of conditionals (Matthieu is an excellent developer so that was to be expected).

    Try something like this in your functions.php or bp-custom.php file

    //Keep the ideastream private
    function private_idea_stream()
    {
    
    	if( is_ideastream() && ! is_user_logged_in() )
    		bp_core_redirect( $bp->root_domain .'/' );
    }
    add_action( 'bp_init', 'private_idea_stream' );

    I’m not sure if this is the right conditional to use but give it a try 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • The question ‘Making a template visible only to logged in users’ is closed to new replies.