• Resolved pix1e

    (@pix1e)


    Hello,

    I’m experiencing an issue with TranslatePress that only occurs when using a language other than the site’s default.

    Here’s what happens:

    When I log in while using a non-default language (e.g., my URL is mydomain.com/lt/login instead of mydomain.com/login), after a successful login I am redirected to the homepage, but the URL ends with #TRPLINKPROCESSED. For example:

    mydomain.com/lt/#TRPLINKPROCESSED

    If I log in using the default language, everything works normally (mydomain.com/), and no #TRPLINKPROCESSED is added.

    Even on unsuccessful login attempts, if I’m using a non-default language, the login page refreshes and #TRPLINKPROCESSED is appended:

    mydomain.com/lt/login#TRPLINKPROCESSED

    I’ve tried the following troubleshooting steps:

    Deactivating all plugins

    Switching themes

    Clearing all caches

    It seems to be related purely to the login redirect handling with TranslatePress.

    Has anyone experienced this or know how to fix it?

    Thanks in advance!

    <?php

    // Start PHP session for flash error messages
    add_action('init', function () {
    if (!session_id()) {
    session_start();
    }
    });

    // Process login on template_redirect
    add_action('template_redirect', function () {

    if (isset($_POST['sev_login_submit'])) {

    $username = sanitize_text_field($_POST['sev_login_username']);
    $password = $_POST['sev_login_password'];
    $remember = !empty($_POST['sev_login_remember']);
    $user = get_user_by('login', $username);
    $redirect_to = wp_get_referer() ? wp_get_referer() : SEV_LOGIN_URL;

    if (!$user) {
    $_SESSION['sev_login_error'] = 'invalid_credentials';
    wp_safe_redirect($redirect_to);
    exit;
    }

    $creds = [
    'user_login' => $username,
    'user_password' => $password,
    'remember' => $remember,
    ];

    $signed_in = wp_signon($creds);

    if (is_wp_error($signed_in)) {
    $_SESSION['sev_login_error'] = 'incorrect_password';
    wp_safe_redirect($redirect_to);
    exit;
    }

    if (in_array('pending', (array) $signed_in->roles)) {
    wp_logout();
    $_SESSION['sev_login_error'] = 'pending_verification';
    wp_safe_redirect($redirect_to);
    exit;
    }

    // Successful login
    wp_safe_redirect(home_url());
    exit;
    }

    });

    // Login form shortcode
    function sev_login_form()
    {
    $error_msg = '';

    if (!empty($_SESSION['sev_login_error'])) {
    $code = sanitize_text_field($_SESSION['sev_login_error']);

    switch ($code) {
    case 'invalid_credentials':
    $error_msg = 'Invalid login credentials.';
    break;

    case 'incorrect_password':
    $error_msg = 'Incorrect password.';
    break;

    case 'pending_verification':
    $error_msg = 'Please verify your email before logging in.';
    break;

    default:
    $error_msg = 'Login failed. Please try again.';
    break;
    }

    unset($_SESSION['sev_login_error']); // Clear flash message
    }

    ob_start();
    ?>

    <form method="post" class="oceanwp-form">

    <?php if ($error_msg): ?>
    <div class="alert error">
    <?php echo esc_html($error_msg); ?>
    </div>
    <?php endif; ?>

    <div class="form-group">
    <label>Username</label>
    <input type="text" name="sev_login_username" required class="oceanwp-form-control">
    </div>

    <div class="form-group">
    <label>Password</label>
    <input type="password" name="sev_login_password" required class="oceanwp-form-control">
    </div>

    <div class="form-group">
    <label>
    <input type="checkbox" name="sev_login_remember" value="1"> Remember Me
    </label>
    </div>

    <div class="form-group">
    <button type="submit" name="sev_login_submit" class="oceanwp-button">Log In</button>
    </div>

    <div class="form-group">
    <p>
    Don't have an account?
    <a href="<?php echo esc_url(SEV_REGISTER_URL); ?>">Register</a><br>
    Forgot password?
    <a href="<?php echo esc_url(SEV_FORGOT_URL); ?>">Reset password</a>
    </p>
    </div>

    </form>

    <?php
    return ob_get_clean();
    }

    add_shortcode('simple_login', 'sev_login_form');
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter pix1e

    (@pix1e)

    I’ve used wp_redirect(home_url()); in other places and everytime I get redirected using that it adds #TRPLINKPROCESSED.

    Thread Starter pix1e

    (@pix1e)

    If I just used, no longer an issue and it works perfectly, but maybe there is better approach?

            header("Location: " . home_url());
    Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    It depends on how the login link is made. If it is from the theme and uses home_url() the link will always have an incorrect link. home_url() will always have the language in it. The plugin or the theme need to use site_url or , much better, the wp_login_url: https://www.example.com/wp-login.php

    However, for custom approaches of login links, we reocmmned to try Peter’s Login Redirect + Profile Builder plugins. In this way, you can redirect the users from wp-login.php in order to be able to log in anyway.

    • This reply was modified 1 month ago by Alex.
    Thread Starter pix1e

    (@pix1e)

    Still same behaviour even with site_url() if using wp_redirect or wp_safe_redirect 🙁 Using something else for register and login isn’t really an option here. I might just use header() here for redirect.

    Thread Starter pix1e

    (@pix1e)

    In the code I provided at first I was already using home_url() btw.

    Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    There is an internal task for our dev team to try removing #TRPLINKPROCESSED from the code. In will be fixed somewhere in the future but until then, you can eliminate it using a custom code:

    <?php
    /**
    * Remove "#TRPLINKPROCESSED" from URLs generated by TRP.
    */
    function trpc_remove_trplinkprocessed( $url, $language, $original_url ) {

    // Remove the fragment if it exists
    $url = str_replace( '#TRPLINKPROCESSED', '', $url );

    return $url;
    }
    add_filter( 'trp_get_url_for_language', 'trpc_remove_trplinkprocessed', 10, 3 );
    • Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality
Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.