Support » Plugin: Force Login » Blank Page after logging in with blank Redirect Value

  • Resolved lesles08

    (@lesles08)


    So we have the following recommended code in our functions file to set a custom login page and allow users to be redirected to the page they were trying to visit upon successful login. However, there are certain wordpress functions (like the password reset page for example) that send users to the login page directly with no redirect value. this results in users being presented with a completely blank (100% white / blank) page after logging in.

    // Force Login plugin modifications —

    // Custom Login URL
    function my_login_page( $login_url, $redirect) {
    return site_url(‘/welcome/?redirect_to=’.$redirect);
    }
    add_filter( ‘login_url’, ‘my_login_page’, 10, 2 );

    As an example here is an example of a url that would result in a blank page after logging in: https://website.com/welcome/?redirect_to=

    Please let me know what should be adjusted or how to provide you with the correct info to troubleshoot further.

    Thank you!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    Hi, thanks for using Force Login!

    I recommend you enable WP_DEBUG mode to determine what error is causing the completely blank page after logging in without a redirect_to value.

    Also, if you need to send users to a specific page when there is no redirect_to value, try using the login_redirect filter. For example:

    /**
     * Filters the login redirect URL.
     *
     * @param string $redirect_to The redirect destination URL.
     * @param string $requested The requested redirect destination URL passed as a parameter.
     * @return string
     **/
    function my_login_redirect( $redirect_to, $requested ) {
      if ( empty( $requested ) ) {
        $redirect_to = home_url( '/mypage/' );
      }
      return $redirect_to;
    }
    add_filter( 'login_redirect', 'my_login_redirect', 10, 2 );

    Thank you so much for your response! I checked the debug.log (wp_debug and wp_debug_log are both set to true) but there’s nothing in the log. I made sure it’s logging errors and it is but just not showing anything related to this issue. Then I tried the code you provided and it isn’t fixing the issue.
    The blank page has no html and there’s no error in the console. I don’t know what to look at or try. Do you have any more ideas that we can try?

    Here’s everything we have in functions that is related to the plugin in case you can see anything (it all works except the new piece you provided today):

    // Force Login plugin modifications -- 
    function my_login_redirect( $redirect_to, $requested ) {
      if ( empty( $requested ) ) {
        $redirect_to = home_url( '/community-welcome/' );
      }
      return $redirect_to;
    }
    add_filter( 'login_redirect', 'my_login_redirect', 10, 2 );
    // Custom Login URL
    function my_login_page( $login_url, $redirect) {
        return site_url('/community-welcome/?redirect_to='.$redirect);
    }
    add_filter( 'login_url', 'my_login_page', 10, 2 );
    
    // Custom Registration URL
    function my_registration_page( $register_url ) {
        return site_url( '/register/', 'login' );
    }
    add_filter( 'register_url', 'my_registration_page', 10, 1 );
    
    /**
     * Filter Force Login to allow exceptions for specific URLs.
     *
     * @param array $whitelist An array of URLs. Must be absolute.
     * @return array
     */
    function my_forcelogin_whitelist( $whitelist ) {
      $whitelist[] = home_url( '/register/' );
      $whitelist[] = home_url( '/activate/' );
      $whitelist[] = home_url( '/request-information/' );
      $whitelist[] = home_url( '/user-community-help/' );
      $whitelist[] = home_url( '/community-welcome/' );
      $whitelist[] = home_url( '/user-community-usage-guidelines/' );
      return $whitelist;
    }
    add_filter( 'v_forcelogin_whitelist', 'my_forcelogin_whitelist' );
    

    Thank you in advance for your help!

    Plugin Author Kevin Vess

    (@kevinvess)

    I made sure it’s logging errors and it is but just not showing anything related to this issue.

    Does this mean there are errors? Are you sure they’re not related to this? First, fix the errors being logged to ensure they’re not causing this.

    I tried the code you provided and it isn’t fixing the issue.

    The code I provided wasn’t intended as a “fix” for the blank screen issue, but I thought it could have helped you avoid that screen by setting a specific login_redirect page when there is no redirect_to value.

    Force Login only redirects visitors to the login screen, requiring them to log in. Anything that happens during or after the login process is not altered by Force Login.

    I suspect this blank screen issue is caused by another plugin or your theme. I recommend you try the following steps to rule out a conflict with your other plugins or theme:

    To test for a theme conflict:

    1. Activate default Twenty-Something theme
    2. Check to see if the issue still occurs
    3. If the issue does not occur after having activated the default “Twenty” theme, your theme is causing this issue.

    To test for a plugin conflict:

    1. Deactivate ALL plugins
    2. Activate Force Login
    3. Check to see if the issue occurs

    If the issue does not occur, one (or more) of your plugins is causing this issue.

    To determine which plugin(s) is causing the issue, follow these steps:

    1. Activate each plugin one by one
    2. Check to see if the issue occurs after each plugin is activated
    Plugin Author Kevin Vess

    (@kevinvess)

    Also, you might want to rewrite / check your theme’s custom filters. They could be the cause of the blank page issue.

    For example, I’d change your login_url filter to this:

    // Custom Login URL
    function my_login_page( $login_url, $redirect, $force_reauth ) {
        $login_url = site_url( '/community-welcome/', 'login' );
        if ( ! empty( $redirect ) ) {
            $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url );
        }
        if ( $force_reauth ) {
            $login_url = add_query_arg( 'reauth', '1', $login_url );
        }
        return $login_url;
    }
    add_filter( 'login_url', 'my_login_page', 10, 3 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.