Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Because it's not working for me. This code checks if a user has just registered. I want to redirect him to a custom page if so. Otherwise, redirect him to the homepage or admin page.

function mylogin_redirect($redirect_to, $url_redirect_to = '', $user = null) {
    if( $user->ID ) {
        $user_info = get_userdata( $user->ID ); 
        // If user_registered date/time is less than 48hrs from now
        // Message will show for 48hrs after registration
        if ( strtotime( $user_info->user_registered ) > ( time() - 172800 ) ) {
            return get_bloginfo('url') . "/custompage/";
        } elseif( current_user_can( 'manage_options' )) {
            return admin_url();
        } else {
            return get_bloginfo('url');
        }
    }
}
add_filter('login_redirect', 'mylogin_redirect');

I get the expected results for the two options but the admin. elseif( current_user_can( 'manage_options' )) { return admin_url(); } doesn't seem to get parsed.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Probably because the global $current_user isn't valid yet, which is used by current_user_can().

However, you can use this instead;

if ($user->has_cap('manage_options')) { return admin_url(); }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.