Support » Plugin: Force Login » Activation link won’t work

  • Resolved 0260n4s

    (@0260n4s)


    I’m not using a custom registration page, but the “register” link would just redirect to the login page. I fixed that with the following code:
    ——————–
    /**
    * 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/’ );
    return $whitelist;
    }
    add_filter( ‘v_forcelogin_whitelist’, ‘my_forcelogin_whitelist’ );
    ———————

    However, when someone registers and clicks the activation link, they just get redirected to the login screen without activation. I’ve tried adding a second “$whitelist[]=” line with “/activate/” and another with “wp-activate.php” but neither works. How can I get the activation link to work?

    Thanks. Awesome plugin, BTW.

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m making some progress. I replaced the previous code with:
    —–
    /**
    * Filter Force Login to allow exceptions for specific URLs.
    *
    * @return array An array of URLs. Must be absolute.
    **/
    function my_forcelogin_whitelist( $whitelist ) {
    // list of single page URLs
    $whitelist[] = site_url( ‘/register/’ );
    $whitelist[] = site_url( ‘/activate/’ );

    // if current page matches conditional tag, add to whitelist
    if ( is_home() || is_sticky() ) {
    $whitelist[] = site_url($_SERVER[‘REQUEST_URI’]);
    }

    return $whitelist;
    }
    add_filter(‘v_forcelogin_whitelist’, ‘my_forcelogin_whitelist’, 10, 1);
    —–

    The activation link still won’t work directly, possibly because Force Login is reading the activation key (blah.com/activate/randomcharacters/) as another subdirectory. BUT, I can go directly to the activation page and manually enter the activation key. It won’t display a confirmation page and instead redirects me to login, but it does activate the account.

    Does anyone know how to make the link work like it’s supposed to and have a confirmation page?

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi– thanks for using Force Login!

    The default WordPress registration URLs use the following format:

    • /wp-login.php?action=register
    • /wp-login.php?action=rp&key=xxxxxxxxxxx&login=username

    Force Login already allows these default login, registration, lost-password URLs to be publicly accessible.

    Based on the code snippets you shared, you are using these custom registration URLs:

    • /register/
    • /activate/

    You might be able to whitelist your custom registration URL by using the wp_registration_url() function (assuming your site uses the register_url filter).

    As for the activation URL, try using one of the FAQ examples of the different methods for whitelisting dynamic URLs on the Force Login Wiki on GitHub.

    Good luck!

    Thank you for your reply. The wp_registration_url suggestion went over my head, I’m afraid. I wouldn’t know how to adapt it specifically to my site. Totally new at this game.

    I’m using the OceanWP theme, so perhaps that theme is forcing a custom registration URL(?) I didn’t realize themes even did that. I haven’t set anything up myself directly.

    All I know is the register link went to …/register/ and if anyone clicked it, they were redirected to the login page. Once I whitelisted /register/ it worked. Likewise, the activation URL is …/activate/[random key], so I whitelisted /activate/ and I can at least manually enter the activation key to activate, but no confirmation page.

    Is the code problematic to use as a workaround? Because, frankly, I’m completely out of options myself. If I can’t use that code, I can’t use force login; people need to get into the site, but I don’t want anyone except registered users getting in.

    Sorry I’m such a noob. I’m the only one working on this before we open a virtual camp on Friday, and with the virus, funding for a programmer is unfortunately not an option.

    Plugin Author Kevin Vess

    (@kevinvess)

    Try this untested code:

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @param bool $url    The visited URL.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass, $url ) {
        $url_path = parse_url( $url, PHP_URL_PATH );
    
        // Allow the registration URLs
        if ( wp_registration_url() == $url ) {
            $bypass = true;
        } elseif ( 'activate' === substr( $url_path, 1, 8 ) ) {
            $bypass = true;
        }
    
        return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
    • This reply was modified 6 months, 1 week ago by Kevin Vess. Reason: Fixed substr() code to start after the initial forward slash of the $url_path
    • This reply was modified 6 months, 1 week ago by Kevin Vess. Reason: Fixed $url_path variable
    0260n4s

    (@0260n4s)

    Thank you for your reply and help, but unfortunately, it didn’t work.

    The Register link worked and allowed me to register an account, but the activation link still redirected to the login page without activation. That was true if I used the full activation link or tried to just go to …/activate/.

    Plugin Author Kevin Vess

    (@kevinvess)

    I had to edit the code example a couple of times, make sure you tried the latest version from the support page.

    Unfortunately, this issue is due to your theme’s custom registration URLs and you will need a developer who can access your site to help troubleshoot the code.

    Good luck!

    0260n4s

    (@0260n4s)

    Thanks for all your help, Kevin. I did use the latest version of the code, so it must just be the theme customization that’s not playing nice. At least the registration link works, and with the other code, new users can manually activate. So I think I’ll be able to work around the limitation for the time being. But again, I really appreciate all the personal attention you’ve given my question. I posted a 5-star review for the plugin on WordPress.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Activation link won’t work’ is closed to new replies.