• Resolved tanmccuin

    (@tanmccuin)


    I’m attempting write a bit of PHP in the template to perform a redirect – essentially, once users are logged in, they are redirected to (for example) site.com/staff/staffnamevariable – this is all working great.

    However, what i’m attempting to do is to first check that the user is logged in already or not, using is_user_logged_in – from there running wp_redirect – to send the user, ideally back to their unique redirect address. (eg site.com/staff/staffnamevariable) so that the user is always pushed to their appropriate user page instead of being presented with the “you are already logged in” screen.

    I’m unsure however, how to access this variable outside of the plugin.

    https://www.ads-software.com/plugins/peters-login-redirect/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tanmccuin

    (@tanmccuin)

    So i’ve managed to answer my own question – and the answer is outside of the plugin, and just uses WP calls. But for anyone looking to accomplish a similar redirect here’s what i’ve got.

    <!-- Already logged in redirect -->
    <?php
    $current_user = get_currentuserinfo();
    if ( is_user_logged_in() ) {
    	wp_redirect( home_url('/client/'. $current_user->user_login .'') ); exit;
    	} else { ?>
    <!-- end Redirect-->

    Newbie question here. Do I put this code in header.php? If so, can I edit it to read something like

    <!-- Already logged in redirect --><?php$current_user = get_currentuserinfo();if ( is_user_logged_in() && is_page('login')) { wp_redirect( home_url('/client/'. $current_user->user_login .'') ); exit; } else { ?><!-- end Redirect—>

    Right now when I try that, the whole site just breaks. If I remove the ‘else {‘ portion, the site works again, but the login page doesn’t. I know this question has been asked millions of times, but I can’t find the answer on the internet and I’ve been looking for hours! (Full disclosure: I do not know php, but I do know other languages).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘use variables in php redirect?’ is closed to new replies.