I am using a custom login page witha script in the functions.php that redirect to a custom "error login" page (adding parameters to the login URL), so it can display the errors in the same page instead of the native login page.
But in some cases, this login page contains some parameters already, when someone is redirected there after trying to access a private page.
For example :
Regular case : They try to access : website.com/login. If there is an error when trying to login, my script redirect to website.com/login?login=empty, and they can try again.
Problematic case : They try to access website.com/protected-page/private, they are automatically redirected to website.com/login?members=%2Fprotected-page%2Fprivate%2. If there is an error when trying to login, my script actualy redirect to website.com/login?login=empty (same as regular case), and what I'm trying to achieve, is to redirect to website.com/login?members=%2Fprotected-page%2Fprivate%2&login=empty, when an error is made.
Keeping this "?members" parameter in the URL allow the form to redirect to the previous page they were trying to access before, after a successful login. Otherwise with the regular case, they are redirected to the general dashboard.
The script that actually manage the redirect when error is this one :
add_action( 'authenticate', 'check_username_password', 1, 3); function check_username_password( $login, $username, $password ) {
$referrer = $_SERVER['HTTP_REFERER'];
if( !empty( $referrer ) && !strstr( $referrer,'wp-login' ) && !strstr( $referrer,'wp-admin' ) ) {
if( $username == "" || $password == "" ){
wp_redirect( get_permalink( 20 ) . "?login=empty" );
exit;
}
}
So the important part here, that will create the error URL is :
wp_redirect( get_permalink( ID ) . "?login=empty" );
I can get my other UTL parameter with "$_GET["members"]", if I do an "echo $_GET["wlfrom"];" it displays successfully the parameter in the page. But even if it looks so simple, I don't manage to add this parameter to the URL. What I'v tried so far :
#1. wp_redirect( get_permalink( ID ) . "?members=" . $_GET["members"] . "?login=empty" );
#2. wp_redirect( get_permalink( ID ) . "?members=" . echo $_GET["members"] . "?login=empty" );
#3. $param = array('members');
wp_redirect( get_permalink( ID ) . "?members=" . $param . "?login=empty" );
//This one returns website.com/?members=array/?login=empty
#4.$param = $_SERVER["PHP_SELF"];
wp_redirect( $param . "?login=empty" );
// This one I cannot use because it displays the native login URL, not my permalink, that's why I need to use "get_permalink" for the first part of the URL
Lately I tried this solution that sounded like the best I had so far :
New hidden field in the login form :
<input type="hidden" name="members" value="<?php echo @$_REQUEST['members']; ?>">
replacing : wp_redirect( get_permalink( ID ) . "?login=empty" ); by
$queryarg='?login=empty';
if(isset($_REQUEST['members']) && $_REQUEST['members']!=''){
$queryarg .='&members='$_REQUEST['members'];
}
wp_redirect( get_permalink( ID ) . $queryarg );
But this solution has returned :
Parse error: syntax error, unexpected '$_REQUEST' (T_VARIABLE) on line 113.
The line involved beeing $queryarg .='&members='$_REQUEST['members']
So any solution to make that happen ? What should I fill up "wp_redirect" with in order to use the parameter from the current URL ?
Thank you !