• Resolved mannyotr

    (@mannyotr)


    I have several custom template pages that take in some parameters, for example:

    https://mywebsite.com/page-slug-name/parameter1/parameter2/

    The template has code that will display a warning message if a user tries to access the page without logging in:

    if ( !is_user_logged_in() )
      echo 'You must be logged in to access this page.';

    However, what is happening is that when the user does log in (using the WP-Members Login widget), they are redirected back to the page, except the parameters are gone. So they end up here:

    https://mywebsite.com/page-slug-name/

    How can I make it so that after login in they are redirected back to the same page, with the same parameters?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    The plugin doesn’t automatically pick up query string arguments through the redirect process. However, you can set up a filter to handle these.

    There is a filter that allows filtering the defaults used in generating the login form, one of which is the page the login will redirect back to – wpmem_login_form_args

    You can hook a function to this to assemble your extra parameters to the link, depending on how you set these up. A basic way would be with the WP function add_query_arg():

    add_filter( 'wpmem_login_form_args', function(){
    	$args['redirect_to'] = add_query_arg( array(
    		'key1' => 'value1',
    		'key2' => 'value2',
    	), 'https://example.com' );
    	return $args;
    });

    More generic example:

    add_filter( 'wpmem_login_form_args', function(){
    	// generate your url, add your query args and put in $some_value
    	$args['redirect_to'] = $some_value;
    	return $args;
    });
    Thread Starter mannyotr

    (@mannyotr)

    I think I might understand what you are saying. But I don’t think it will help me.

    If I understand what you are saying, I would need to create a filter kinda like this:

    add_filter( 'wpmem_login_form_args', function(){
    	$some_value = 'https://mywebsite.com/page-slug-name/parameter1/parameter2/';
    	$args['redirect_to'] = $some_value;
    	return $args;
    });

    Is that right?

    If that is right, that would work for only one page. But that won’t help me because I have over a dozen different pages I need this to work for. For example, I need this to work for all these pages:

    https://mywebsite.com/page-slug-name2/parameter1/
    https://mywebsite.com/page-slug-name3/parameter1/parameter2/parameter3/
    https://mywebsite.com/page-slug-name4/parameter1/parameter2/

    So how would that work?

    Plugin Author Chad Butler

    (@cbutlerjr)

    Is that right?

    Kind of. I guess by saying “generate your url, add your query args and put in $some_value” I was suggesting that you could put in whatever kind of logic you need based on the needed outcome. Based on your original question (“How can I make it so that after login in they are redirected back to the same page, with the same parameters?”), that should amount to appending any parameters to the current URL (which could be retrieved any number of ways).

    I’m operating under that assumption that this is a custom process ultimately using the WP rewrite API (using add_rewrite_rule), in which case, it would make sense for you to implement a process using get_query_var and just write the URL based on what is passed. If this is a custom process you’ve written, then I would assume you would be able to do that. If not, it’s outside the scope of what I can help you with here since I don’t know (1) the possible variables that are being added and (2) the rewrite rules being used to add them.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Login Redirect – Custom Template with Parameters’ is closed to new replies.