• Hi, I am using the free version of Polylang to make may site mutilingual. I have created pages in second language with TML Actions but URLs under e.g. Log in form (Lost password and Register) moving to Page with first language. How to force them to redirect to the same page but in language that I am actualy using?

    Best,

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Jeff Farthing

    (@jfarthing84)

    You would probably need to filter TMLs action links adding the current language to the URL. Theoretically, it would look something like this:

    
    function add_language_to_tml_action_url( $url ) {
        // This is a hypothetical function - you'll need to ask the developers of Polylang if such a function exists.
        if ( function_exists( 'add_current_language_to_url' ) ) {
            $url = add_current_language_to_url( $url );
        }
        return $url;
    }
    add_filter( 'tml_get_action_url', 'add_language_to_tml_action_url' );
    
    Thread Starter milosztor

    (@milosztor)

    I think I can change it by getting current language and filter action links but this code doesn’t work for me :/

    function tml_action_url( $url, $action, $instance ) {
    	if ( 'register' == $action )
    		$url = '/test/';
    	return $url;
    }
    add_filter( 'tml_action_url', 'tml_action_url', 10, 3 );
    Plugin Author Jeff Farthing

    (@jfarthing84)

    The filter is tml_get_action_url.

    Thread Starter milosztor

    (@milosztor)

    I have changed urls but when I click e.g. log in button or get my new password, page reloads and nothing happens. My code to change link to e.g. lost password page:

    function tml_action_url_lost( $url, $action, $instance ) {
    	if(pll_current_language() == "en") {
    		if('lostpassword' == $action)
    			$url = '/en/lost-password/';
    	}
    	return $url;
    }
    add_filter( 'tml_get_action_url', 'tml_action_url_lost', 10, 3 );
    Plugin Author Jeff Farthing

    (@jfarthing84)

    You will need to “tell” TML the action you are trying to handle as TML ties its actions to the slugs/URLs found in its settings.

    Try something like this:

    
    function parse_request_callback( $wp ) {
        if ( 'en/lostpassword' == trim( $wp->request, '/' ) ) {
            $wp->set_query_var( 'action', 'lost password' );
        }
    }
    add_action( 'parse_request', 'parse_request_callback' );
    
    Thread Starter milosztor

    (@milosztor)

    It worked for lostpassword but not working for login and register :/

    Thread Starter milosztor

    (@milosztor)

    Any ideas?

    Plugin Author Jeff Farthing

    (@jfarthing84)

    
    function parse_request_callback( $wp ) {
        if ( 'en/login' == trim( $wp->request, '/' ) ) {
            $wp->set_query_var( 'action', 'login' );
        } elseif ( 'en/register' == trim( $wp_request, '/' ) ) {
            $wp->set_query_var( 'action', 'register' );
        } elseif ( 'en/lostpassword' == trim( $wp->request, '/' ) ) {
            $wp->set_query_var( 'action', 'lostpassword' );
        }
    }
    add_action( 'parse_request', 'parse_request_callback' );
    
    Thread Starter milosztor

    (@milosztor)

    My bad, I made a mistake ?? Now it is working but not for “register”.

    • This reply was modified 5 years, 4 months ago by milosztor.
    • This reply was modified 5 years, 4 months ago by milosztor.
    Plugin Author Jeff Farthing

    (@jfarthing84)

    Is the path to your register action “/en/register”?

    Thread Starter milosztor

    (@milosztor)

    That’s right.

    Plugin Author Jeff Farthing

    (@jfarthing84)

    There was a typo in my code. Try this:

    
    function parse_request_callback( $wp ) {
        if ( 'en/login' == trim( $wp->request, '/' ) ) {
            $wp->set_query_var( 'action', 'login' );
        } elseif ( 'en/register' == trim( $wp->request, '/' ) ) {
            $wp->set_query_var( 'action', 'register' );
        } elseif ( 'en/lostpassword' == trim( $wp->request, '/' ) ) {
            $wp->set_query_var( 'action', 'lostpassword' );
        }
    }
    add_action( 'parse_request', 'parse_request_callback' );
    

    Jeff very nice work on the plugin.
    I was able to get different login for different languages.
    I also got the notification extension. I was able to place custom categories for the custom notifications.
    I was wondering if i could trigger a custom notification label based on language
    this the code
    // login in Arabic
    // pll identify language for poly lang pluin

    function tml_action_url_login( $url, $action, $instance ) {
    if(pll_current_language() == “ar”) {
    if(‘login’ == $action)
    $url = ‘/ar/login-2/’;
    }
    return $url;
    }
    add_filter( ‘tml_get_action_url’, ‘tml_action_url_login’, 10, 3 );

    function tml_action_url_register( $url, $action, $instance ) {
    if(pll_current_language() == “ar”) {
    if(‘register’ == $action)
    $url = ‘/ar/register-2/’;
    }
    return $url;
    }
    add_filter( ‘tml_get_action_url’, ‘tml_action_url_register’, 10, 3 );

    function tml_action_url_lost( $url, $action, $instance ) {
    if(pll_current_language() == “ar”) {
    if(‘lostpassword’ == $action)
    $url = ‘/ar/lostpassword-2/’;
    }
    return $url;
    }
    add_filter( ‘tml_get_action_url’, ‘tml_action_url_lost’, 10, 3 );

    function tml_action_url_resetpass( $url, $action, $instance ) {
    if(pll_current_language() == “ar”) {
    if(‘resetpass’ == $action)
    $url = ‘/ar/resetpass-2/’;
    }
    return $url;
    }
    add_filter( ‘tml_get_action_url’, ‘tml_action_url_resetpass’, 10, 3 );

    function parse_request_callback( $wp ) {
    if ( ‘ar/login-2’ == trim( $wp->request, ‘/’ ) ) {
    $wp->set_query_var( ‘action’, ‘login’ );
    } elseif ( ‘ar/register-2’ == trim( $wp->request, ‘/’ ) ) {
    $wp->set_query_var( ‘action’, ‘register’ );
    } elseif ( ‘ar/lostpassword-2’ == trim( $wp->request, ‘/’ ) ) {
    $wp->set_query_var( ‘action’, ‘lostpassword’ );
    }
    }
    add_action( ‘parse_request’, ‘parse_request_callback’ );

    //Labels for custom notification

    function register_custom_tml_notification_triggers() {
    tml_notifications_register_trigger( ‘Arabic Reset Password’, array(
    ‘label’ => __( ‘Arabic Reset Password’, ‘theme-my-login-notifications’ ),

    ) );
    tml_notifications_register_trigger( ‘English Reset Password’, array(
    ‘label’ => __( ‘English Reset Password’, ‘theme-my-login-notifications’ ),

    ) );
    }
    add_action( ‘init’, ‘register_custom_tml_notification_triggers’ );

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘URLs under Login and Register forms’ is closed to new replies.