Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

[Support request] Link directly to membership URL via login (swpm_after_login_redirect_url)

Simple Membership Plugin › Forums › Simple Membership Plugin › Link directly to membership URL via login (swpm_after_login_redirect_url)

  • This topic has 0 replies, 1 voice, and was last updated 8 years, 7 months ago by r_ag.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • February 15, 2018 at 8:58 am #13370
    r_ag
    Participant

    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&#8217; 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.

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy