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.

So i'm fairly certain this probably has something to do with the fact that I'm using a custom role I've set up in my functions.php file with almost 0 permissions. However, I'm still able to access the dashboard, just I get sent to profile.php on login instead of dashboard. I want my user_role to get sent to the dashboard each time as I have a custom widget set up for them there. I can't seem to find the function in the codex and the necessary hook to set this up? It looks like if I was using a custom login form I could use wp_login_form() but I just want to use the default login form without hacking the admin file so its not effected by updates. Anyone know the function I'm needing. Cant' seem to feed google the right terminology.

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

Filter 'login_redirect'.

Sample code, not tested:

add_filter( 'wp_login', 'wpse_78150_login_redirect' );

function wpse_78150_login_redirect( $url )
{
    # uncomment the next line for debugging
    # var_dump( wp_get_current_user() ); exit;

    if ( ! current_user_can( 'custom_role' ) )
        return $url;

    return admin_url();
}
share|improve this answer
    
when I log in with my custom role I'm still being taken to profile.php. I was supposed to substitute the name of my custom role for 'custom_role' correct? –  John B Jan 3 '13 at 21:58
    
@JohnB Yes, that should do the trick. I have added a debug helper to my suggestion. Try it, and add the result to your question. –  toscho Jan 3 '13 at 22:05
    
WEll when I var_dump(! current_user_can( 'Coach' ), $url); exit; I'm getting true and ....myurl..../wp-admin/ but when it comes up false it goes to wp-admin/index.php. I'm beginning to wonder if its possibly redirecting to profile.php after hitting index.php –  John B Jan 3 '13 at 22:26
    
yeah it was something else. Now it works. Thanks. –  John B Jan 3 '13 at 23:38
    
Hey @JohnB, What was that something else, if you can remember it. I'm having a similar issue where when I do a complete cold login, my user gets sent to the profile page using the above code. When the user is already logged in and then I hit the login screen again and log in, it takes me to the desired page. Any thoughts? –  Brent Apr 26 '13 at 19:50
show 3 more comments

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.