- This topic has 0 replies, 1 voice, and was last updated 8 years, 7 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
WordPress Membership Plugin
Simple Membership Plugin › Forums › Simple Membership Plugin › Link directly to membership URL via login (swpm_after_login_redirect_url)
Hi,
I have a solution where all users are redirected to login if they are not already logged in.
However the customer wants to be able to send links to specific pages to the site users by mail. The problem is that if the users are not logged in, they are redirected to login and the link URL is lost.
To fix this my idea is to save the original URL before redirecting to login and then use swpm_after_login_redirect_url to redirect to the original URL after login. However I cannot get it to work. My current code is like this:
$originalURL
add_filter( 'pre_get_posts', 'swpm_auto_redirect_non_members' );
function swpm_auto_redirect_non_members($originalURL) {
if (!current_user_can( 'manage_options' )) {
// save original URL
$originalURL = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// if not logged in, redirect to login
if(!SwpmMemberUtils::is_member_logged_in() && !(is_page('membership-login' ) || is_page('password-reset') )){
//echo '<!-- page is test -->';
wp_redirect( get_home_url().'/membership-login/' );
}
if(is_page('membership-login')){
echo '<!-- page is membership-login -->';
}
}
}
add_filter('swpm_after_login_redirect_url', 'redirectToURL');
function redirectToURL($originalURL) {
return $originalURL;
}
What am I doing wrong? If I replace return $originalURL with a static URL like ‘https://www.google.com’ it works, so I guess my error lies in assigning a correct URL to $originalURL. I have also tried using global $originalURL inside the functions instead of passing it as a parameter.