• Resolved 8bit7

    (@8bit7)


    Expected: a logged out user clicks a link to go to their profile, it redirects to the login page

    Actual: it refreshes the page (or possibly fails to redirect?)

    Not sure if bug or feature 🙂

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter 8bit7

    (@8bit7)

    I added the code below to functions.php to try to force it, but it’s still not redirecting.

    function add_login_redirect() {
        if ( is_page('profile')  &&  !is_user_logged_in() ){
            wp_redirect( site_url( '/login' ) );
        }
    }
    
    add_action('template_redirect', 'add_login_redirect');
    
    Thread Starter 8bit7

    (@8bit7)

    So, got it working in functions.php, but still would be awesome to have it in the plugin. Here’s the code for future googlers.

    // Redirect logged out users who visit the profile page
    function login_redirect() {
    
        // Get current page 
        global $pagenow;
    
        // Check to see if user in not logged in and also on the profile page
        if(!is_user_logged_in() && $pagenow = is_page('profile'))
              // If user is, redirect to login form.
              auth_redirect();
    }
    
    add_action( 'wp', 'login_redirect' );
    Plugin Contributor Paolo

    (@paoltaia)

    The behavior you’re experiencing is expected, but your suggestion has value. I’ll pass your request on to our development team for consideration.

    Thanks,

    Thread Starter 8bit7

    (@8bit7)

    oh cool, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Clicking Profile Page When Logged Out Doesn’t Redirect To Login Page’ is closed to new replies.