Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @erfanmhd

    Please use the “CODE” feature of the text editor to highlight the links. It is rendered instead so your topic is messed up.

    Regards,

    Thread Starter Erfan MHDi

    (@erfanmhd)

    Ops, Sorry about that, didn’t notice it.

    hello,
    i have a question about redirecting user after SignIn, Up or Out!
    as im using wp multisite, i need to redirect user from SubSite to main site because i only have ultimate member and SignIn form in main site and then after successful login, redirect user back to the ‘account’ page of the sub site he/she was before clicking the login link.

    i’ve tried this link using ‘?redirect_to’ url parameter

    <a href="<?php echo network_home_url() . 'signin/?redirect_to=' . home_url() . '/account/'; ?>" >

    to redirect user from this url => example.com/subsite1
    to this url => example.com/signin (multisite main-site)
    and after successful login i need user to be redirected to => example.com/subsite1/account

    and it was working fine with WordPress multisite in subdirectory mode,
    but as i had to switch to subdomain mode it looks like the ?redirect_to parameter is being skipped.
    what i’m trying to do in subdomain mode is

    redirect user from this url => subsite1.example.com
    to this url => example.com/signin (multisite main-site)
    and after successful login i need user to be redirected to => subsite1.example.com/account
    but currently user is being redirected to example.com after successful login.

    i have tried to encode the ?redirect_to value but it make no different with none of these links:

    <a href="https://example.com/signin/?redirect_to=https://subsite1.example.com/account/" >

    <a href="https://example.com/signin/?redirect_to=https%3A%2F%2Fsubsite1.example.com%2Faccount%2F" >

    how can i use redirect_to url parameter to redirect user from sub site to main site login form and redirect him back to the sub site he was at ?

    Thanks in Advance!

    • This reply was modified 3 years, 5 months ago by Erfan MHDi.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @erfanmhd

    You can try adding this code snippet to your Main site’s theme/child-theme functions.php file or use the Code Snippets plugin to run the code:

    add_action("wp_login","um_062921_multisite_redirect_after_login",1);
    function um_062921_multisite_redirect_after_login(){
      
        if( isset( $_REQUEST['redirect_to'] ) && ! empty($_REQUEST['redirect_to']) ){
    	   wp_redirect( $_REQUEST['redirect_to']  ); exit;
    	}
    }

    The above code will force the login to redirect to a subsite.

    Regards,

    Thread Starter Erfan MHDi

    (@erfanmhd)

    Hello @champsupertramp,
    it’s working just they way i was looking for,

    Thanks mate ??

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @erfanmhd

    Thanks for letting us know.

    Regards,

    Thread Starter Erfan MHDi

    (@erfanmhd)

    Hello Again @champsupertramp,
    there is a problem with the function you kindly mentioned above in some urls that contains another query parameters.

    right now i’ve this redirect function on my functions.php

    function RedirectToURLParameter() {
        if( isset( $_REQUEST['redirect_to'] ) && ! empty($_REQUEST['redirect_to']) ){
    		wp_redirect( $_REQUEST['redirect_to']  ); 
    		exit;
    	}
    }
    add_action("wp_login","RedirectToURLParameter",1);
    add_action("wp_logout","RedirectToURLParameter",1);

    when url is like this:
    https://www.example.com/signin/?redirect_to=https://store.example.com/account/

    it’ll open this url after successful login:
    https://store.example.com/account/

    but when the url is like this one:
    https://www.example.com/signin/?redirect_to=https://store.example.com/account/?wishlist_notice=true&add_to_wishlist=647

    it’ll open this url after successful login:
    https://store.example.com/account/?wishlist_notice=true

    what i need to be open after login is this url:
    https://store.example.com/account/?wishlist_notice=true&add_to_wishlist=647

    or maybe hopefully strip the wishlist_notice=true& and make the final url like this :
    https://store.example.com/account/?add_to_wishlist=647

    Thanks in Advance for your time and friendly help. ??

    • This reply was modified 3 years, 5 months ago by Erfan MHDi.
    • This reply was modified 3 years, 5 months ago by Erfan MHDi.
    • This reply was modified 3 years, 5 months ago by Erfan MHDi.
    Thread Starter Erfan MHDi

    (@erfanmhd)

    up!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @erfanmhd

    You can try this one:

    function RedirectToURLParameter() {
        if( isset( $_REQUEST['redirect_to'] ) && ! empty($_REQUEST['redirect_to']) ){
          $redirect_to = $_REQUEST['redirect_to'] ;
          $redirect_to = str_replace("wishlist_notice=true&","", $redirect_to );
    		wp_redirect( $redirect_to  ); 
    		exit;
    	}
    }
    add_action("wp_login","RedirectToURLParameter",1);
    add_action("wp_logout","RedirectToURLParameter",1);
    

    Regards,

    Thread Starter Erfan MHDi

    (@erfanmhd)

    Hi @champsupertramp,

    Thanks for your response, but it seems there is a problem.
    using this line of codes:

    function RedirectToURLParameter() {
        if( isset( $_REQUEST['redirect_to'] ) && !empty($_REQUEST['redirect_to']) ) {
    		$redirect_to = $_REQUEST['redirect_to'] ;
    		$redirect_to = str_replace("wishlist_notice=true&","", $redirect_to );
    		wp_redirect( $redirect_to  ); 
    		exit;
    	}
    }
    add_action("wp_login","RedirectToURLParameter",1);
    add_action("wp_logout","RedirectToURLParameter",1);

    and following this link :

    https://www.example.com/signin/?redirect_to=https://store.example.com/account/?wishlist_notice=true&add_to_wishlist=609

    is ending up with this link after successful login:

    https://store.example.com/account/?wishlist_notice=true

    instead of this one:

    https://store.example.com/account/?add_to_wishlist=609

    the “str_replace” is converting the url correctly but the redirect function is redirection to wrong url.
    it seems what’s comes after “&” in “redirect_to=” value is being skipped in first place and the redirect function is redirecting to a url like this:
    https://store.example.com/account/?wishlist_notice=true

    any idea ?

    • This reply was modified 3 years, 4 months ago by Erfan MHDi.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @erfanmhd

    Are you able to add this urlencode() to your link where it adds the Redirect To?

    e.g. echo "https://www.example.com/signin/?redirect_to=" . urlencode("https://store.example.com/account/?wishlist_notice=true&add_to_wishlist=609");

    Regards.

    Thread Starter Erfan MHDi

    (@erfanmhd)

    Hello @champsupertramp,

    it seems that the problem was using $_REQUEST['redirect_to']
    i manage to fix the problem by using $_SERVER['QUERY_STRING'] instead.
    it seems to be working just fine.
    here is my final code in case anyone else faces the same issue:

    function RedirectToURLParameter() {
    	if( isset( $_GET['redirect_to']) && !empty($_REQUEST['redirect_to']) ) { 
    		$redirect_to = $_SERVER['QUERY_STRING'];
    		$redirect_to = str_replace("redirect_to=","", $redirect_to );
    		$redirect_to = str_replace("wishlist_notice=true&","", $redirect_to );
    		wp_redirect( $redirect_to  ); 
    		exit;
    	}
    }
    add_action('wp_login','RedirectToURLParameter',1);
    add_action('wp_logout','RedirectToURLParameter',1);

    Thank you for your helps @champsupertramp,

    P.S: please Do tell me if there is any thing unordinary in my code or if it might have any security issue ( clearly i’m not the expert here ?? ).

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @erfanmhd

    The code looks good! Glad you’ve resolved it. Also, thanks for letting us know how you resolve the issue.

    Regards,

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Redirect After SignIn or SignOut or SignUp’ is closed to new replies.