• Resolved PSS

    (@airtasker6)


    Hi,

    We have a custom login URL setup with the Hide Backend feature. We also have a popular code snippet that redirects user on the frontend login page when using the Elementor login form as follows:

    add_action( 'wp_login_failed', 'elementor_form_login_fail', 9999999 );
    function elementor_form_login_fail( $username ) {
        $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
        // if there's a valid referrer, and it's not the default log-in screen
        if ((!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') )) {
            //redirect back to the referrer page, appending the login=failed parameter and removing any previous query strings
            //maybe could be smarter here and parse/rebuild the query strings from the referrer if they are important
            wp_redirect(preg_replace('/\?.*/', '', $referrer) . '?login=failed' );
            exit;
        }
    }
    // This is also important. Make sure that the redirect still runs if the username and/or password are empty.
    add_action( 'wp_authenticate', 'elementor_form_login_empty', 1, 2 );
    function elementor_form_login_empty( $username, $pwd ) {
        $referrer = $_SERVER['HTTP_REFERER'];  // where did the post submission come from?
     if ( empty( $username ) || empty( $pwd ) ) {
        if ((!strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') )) {
            //redirect back to the referrer page, appending the login=failed parameter and removing any previous query strings
            //maybe could be smarter here and parse/rebuild the query strings from the referrer if they are important
            wp_redirect(preg_replace('/\?.*/', '', $referrer) . '?login=failed' );
            exit;
        }
       exit();
     }
    }

    We have found is this code snippet does not work with iThemes hide backend feature. The backend URL loads with ‘?login=failed’ appended to the URL and we are unable to login to wp-admin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @airtasker6,

    Thank you for reaching out to us.

    It appears that the custom code conflicts with the iThemes Security plugin.

    I’ll suggest not using the hide backend feature if the code is required for your preferences. Here is an article stating that the hide backend is not really a security strategy that we recommend: 

    https://help.ithemes.com/hc/en-us/articles/229240588-iThemes-Security-Hide-Backend

    Thus, not using the feature should not decrease the security standards.

    Looking forward to your response.

    Best regards,
    Shalom

    Thread Starter PSS

    (@airtasker6)

    “It appears that the custom code conflicts with the iThemes Security plugin.”

    Obviously, or we would have needed to open this support thread. We were hoping you would have some sort of fix for this but looks like no.

    Hi @airtasker6,

    The code snippet itself clearly states:

    //… and removing any previous query strings
    //maybe could be smarter here and parse/rebuild the query strings from the referrer if they are important

    So make the code snippet smarter in order to retain the Hide Backend itsec-hb-token=[your chosen hide backend slug] query string.

    +++ To prevent any confusion, I’m not iThemes +++

    Thread Starter PSS

    (@airtasker6)

    Hi @nlpro

    We have managed to do that and have it working in conjunction with iTheme’s custom login URL feature.

    Thanks for your reply. I’ll close this ticket now.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Error with Custom Login URL’ is closed to new replies.