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.
Add a comment
|
1 Answer
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();
}
-
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 BCommented Jan 3, 2013 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.– fuxia ♦Commented Jan 3, 2013 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 BCommented Jan 3, 2013 at 22:26
-
-
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?– BrentCommented Apr 26, 2013 at 19:50