Support » Fixing WordPress » First time login redirect – amend code for ‘subscriber’ user role only

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,

    If you add this “if” to your first login check like so it should help:

    if ( $first_login == ‘1’ ) && ( current_user_can( ‘subscriber’ ) )
    echo “this user is a subscriber and it is their first time logging in”;

    If you need to explore this further here is my source:

    https://wordpress.stackexchange.com/questions/60272/find-out-if-logged-in-user-is-not-subscriber

    Hope this helps!

    Thread Starter dan87manc

    (@dan87manc)

    Hey @whoudini

    I appreciate the reply!

    I’ve tried the above and a few different variations but I keep getting:

    ‘Parse error: syntax error, unexpected ‘&&’ (T_BOOLEAN_AND) ..’

    Do you have any ideas for getting around this?

    Thanks again

    My apologies, try this instead:

    if( $first_login == '1' and current_user_can( ‘subscriber’ ) )  {
            // update meta after first login
            update_user_meta($user_id, 'prefix_first_login', '0');
            // redirect to given URL
            wp_redirect( 'http://www.example-url.com' );
            exit;
        }

    Alternatively, if the above does not work; try this:

    if( $first_login == '1' )  {
     if( current_user_can( ‘subscriber’ ) )  {
            // update meta after first login
            update_user_meta($user_id, 'prefix_first_login', '0');
            // redirect to given URL
            wp_redirect( 'http://www.example-url.com' );
            exit;
        }
    }

    Hope this helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.