• Resolved HexEgg

    (@hexegg)


    Hi. A question about redirection to private page when WPML is installed:

    I have two languages on my site (EN, FR). The default site language is EN and when I create a new user it automatically creates EN version of the private page as well as the FR version duplicate (managed to set it up with WPML). I made two portal pages for each language (though the shortcode on those pages is the same) and assigned redirect URLs for the login form. Now when a new user comes to the site, switches to FR version and is trying to login he/she is redirected to EN version of the private page. Is there a way to add a custom function to my functions.php file to make it redirect to the correct language page?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Georgian Cocora

    (@raster02)

    Hello @hexegg,

    What are you using for logging in your users ? The normal WordPress wp-login.php ?

    Regards.

    Thread Starter HexEgg

    (@hexegg)

    Im using your profile builder.

    Plugin Author Georgian Cocora

    (@raster02)

    Hello @hexegg,

    Can you show me how you created the duplicate page in another language with WPML ?
    I’m interested in the URL and if it actually works, doesn’t seem to be working for me.

    You have defined a redirect in the [wppb-login] shortcode which takes you to the private page ?

    Regards.

    Thread Starter HexEgg

    (@hexegg)

    I found this snippet on the WPML support forum. I put it into my functions.php file on in child theme:

    //**** WPML post auto duplication ****/
    add_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
    function my_duplicate_on_publishh( $post_id ) {
    
      $post = get_post( $post_id ); 
          
        //don't save for autosave
     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
          return $post_id;
      }
        //dont save for revisions
      if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
          return $post_id;
      }
       
        //we need this to avoid recursion see add_action at the end
      remove_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
        
            //make duplicates if the post being saved
            //#1. itself is not a duplicate of another or
            //#2. does not already have translations
       
          $is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
       
          if ( !$is_translated ) {
             		do_action( 'wpml_admin_make_post_duplicates', $post_id );
          }
       
        //must hook again - see remove_action further up
      add_action( 'wp_insert_post', 'my_duplicate_on_publishh' );
    }

    Though it duplicates not just private pages, but any new created page.

    Plugin Author Georgian Cocora

    (@raster02)

    Hello @hexegg,

    I tried to set this up in my environment, but it doesn’t seem to work.

    Anyhow, this is how you can set the redirect URL based on the language in Profile Builder. You need to add the following code to your website:

    add_shortcode('wppbc_login_with_wpml_redirect', 'wppbc_login_with_wpml_redirect');
    function wppbc_login_with_wpml_redirect($atts,$content){
    	$my_current_lang = apply_filters( 'wpml_current_language', NULL );
    
    	if(isset($my_current_lang) && $my_current_lang == 'en')
    		return do_shortcode('[wppb-login redirect_url="https://yourdomain.com/en/page"]');
    	else if (isset($my_current_lang) && $my_current_lang == 'fr')
    		return do_shortcode('[wppb-login redirect_url="https://yourdomain.com/fr/page"]');
    }

    Make sure to adjust the URLs to the ones you want to use (it works only with URLs that belong to your domain because a safe redirect is done). And then instead of using the [wppb-login] shortcode just use [wppbc_login_with_wpml_redirect] and the redirect should be done based on the selected language.

    Regards.

    Thread Starter HexEgg

    (@hexegg)

    Well this is just to redirect a user during login to the Portal page from where the user is redirected to his/her private page. But the Portal page itself by default redirects user to ENG only version of the private page (or whatever language is set as main for the site). By the way we’re using different domains for each language (mysite.com and mysite.fr).
    I need the Portal to do the following:
    1. Check what site language is currently being used.
    2. Redirect to the according user’s private-page (if a user came from .fr domain, then redirect him/her to the “mysite.fr/private-page/username”, else redirect to “mysite.com/private-page/username”).

    Plugin Author Georgian Cocora

    (@raster02)

    Hello @hexegg,

    We can’t change the redirect URL from Client Portal and even if we do, it doesn’t work with WPML.
    Probably support needs to be added. For example, I can never access the duplicate of the private page that you can create with WPML for another language. This means that even if you send the user to that URL, he will be sent to the en version or the one you created first.

    I don’t think we can help you with this issue at this time.

    Regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Redirect to Chosen Language Page’ is closed to new replies.