Skip to:
Content
Pages
Categories
Search
Top
Bottom

Setup login for private forum?

Viewing 18 replies - 1 through 18 (of 18 total)
  • Hi,

    To fix when the user logs out, you could use this code. Add it into your functions.php and change $url to whatever you want as page.

    function casiepa_logout ($redirect_to) {
    	$url='/forums/' ;
    	$redirect_to = '<a href="' . wp_logout_url( $url ) . '" class="button logout-link">' . esc_html__( 'Log Out', 'bbpress' ) . '</a>' ;
    	return $redirect_to ;
    	}
    	
    add_filter ('bbp_get_logout_link', 'casiepa_logout') ;

    Pascal.


    phudack7
    Participant

    @phudack7

    Thanks Pascal. My main concern is that because its a private forum, theres no login when someone arrives there. Instead they get a ‘page not found’ error. Is there a way to have the login form appear if an unregistered user visits the forum page?

    Different options then. You could try the below code in your 404.php file:

    <?php $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    
    	$actual_link = explode('/',$actual_link);
    	if($actual_link[3]=="forums") { ?>
    	<h2 class="article-title"><?php _e( 'This forum is private. Please login to access this forum' ); ?></h2>
    	<?php } else {?>
    <img src="<?php echo get_template_directory_uri();?>/assets/images/404_image.png"><br>

    Hope it helps…
    Pascal.

    Or you could use a redirection plugin like mentioned on this page: https://premium.wpmudev.org/blog/wordpress-404-plugin/

    Hope it helps…
    Pascal.


    phudack7
    Participant

    @phudack7

    Thanks Pascal. Both of these worked great. One last question, I have a login page that’s separate from the forum page. Do you have a code I can put in my functions file that will redirect a user to the forum page once they have logged in?

    Thanks so much

    Hi,

    Check out ‘Peterโ€™s Login Redirect plugin’.

    I saw somebody also using this (but did not test myself):

    function login_redirect( $redirect_to, $request, $user ){
        return home_url('forums');
    }
    add_filter( 'login_redirect', 'login_redirect', 10, 3 );

    Pascal.


    lenwej
    Participant

    @lenwej

    Excellent – thanks!


    RONO2
    Participant

    @rono2

    Pascal, so where exactly would I put those particular 3 codes at in the wordpress? or actually in the css section of the theme editor?


    RONO2
    Participant

    @rono2

    And is there a simple way to make a register link for the forums if set to private? because there’s no way to login if they don’t register ๐Ÿ˜›

    Code can go in functions.php of your (child) theme: https://codex.bbpress.org/functions-files-and-child-themes-explained/

    Pascal.


    RONO2
    Participant

    @rono2

    got ya, and that will affect my parent forum correct? My forum isn’t a child theme. Thanks for all your help

    Yep, what you put there is valid for your whole WordPress instance.
    Pascal.


    RONO2
    Participant

    @rono2

    For private forums, will these also create a register for the forum capability? An what is the easiest way to make a child theme?


    Robkk
    Moderator

    @robkk

    @rono2 mostly focus on this guide below.

    https://codex.wordpress.org/Child_Themes


    abufrank
    Participant

    @abufrank

    For fixing the “page-not-found” when accessing a private forum, I found that when I placed Pascals code into the 404 page (great code by the way), the browser still flags the 404. So instead, I moved it to the functions.php file using the following:

    //redirect user to log in page if accessing forum from external link
    add_action( 'template_redirect', 'forum_redirect_from_external_link' );
    function forum_redirect_from_external_link() {
      $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
      $actual_link = explode('/',$actual_link);
      if($actual_link[3]=="forums" && !is_user_logged_in() ) {
        wp_redirect( home_url('your-forum-log-in-page-here') ); 
          exit;
      }
    }

    I hope this was constructive… ๐Ÿ™‚


    semperaye
    Participant

    @semperaye

    I’m still getting “page not found” with abufrank’s code.


    semperaye
    Participant

    @semperaye

    Shouldn’t there be some functions code in there somewhere? I’m using the php code snippets plugin so I don’t really know how to code these things i’m just copying and pasting into that…

Viewing 18 replies - 1 through 18 (of 18 total)
  • You must be logged in to reply to this topic.
Skip to toolbar