0

I am using BBPress. Links to the forum (for example: https://www.xy.com/topic/test/) are being redirected to a custom login page like so:

if ( is_bbpress() && !is_user_logged_in() ) {

 wp_redirect( 'https://www.xy.com/intranet'); }

The users can successfully login, but unfortunately always end up on the same page since the redirect causes a loss of the original URL. Any ideas?

1 Answer 1

0
if ( is_bbpress() && !is_user_logged_in() ) {
  wp_redirect( 'https://www.xy.com/intranet');  // if this redirects to your login page 
}

And this is your login form:

$args = array(
        'echo' => true,
        'redirect' => site_url( $_SERVER['REQUEST_URI'] ), // this will redirect
        'form_id' => 'loginform',
        'label_username' => __( 'Username' ),
        'label_password' => __( 'Password' ),
        'label_remember' => __( 'Remember Me' ),
        'label_log_in' => __( 'Log In' ),
        'id_username' => 'user_login',
        'id_password' => 'user_pass',
        'id_remember' => 'rememberme',
        'id_submit' => 'wp-submit',
        'remember' => true,
        'value_username' => NULL,
        'value_remember' => false );

wp_login_form( $args );

So what happens above us this:

  • If you are on BB and you are not logged in, your will be redirected to the login page
  • And once you are logged in, you will return to the previous page

I haven't tested the script, but it is logically correct.

3
  • Can you also explain, what it does please?
    – bravokeyl
    Nov 14, 2016 at 10:36
  • Thanks for the answer! That doesn't seem to work though. The referring link gets lost when redirecting to the login page already.
    – Simon
    Nov 14, 2016 at 10:44
  • I think I know what the problem is... I have updated the script for you above.
    – user23355
    Nov 14, 2016 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.