Advertisement
srikat

Untitled

Apr 14th, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. /**
  2. * Redirect user after successful login.
  3. *
  4. * @param string $redirect_to URL to redirect to.
  5. * @param string $request URL the user is coming from.
  6. * @param object $user Logged user's data.
  7. * @return string
  8. */
  9. function my_login_redirect( $redirect_to, $request, $user ) {
  10. //is there a user to check?
  11. if ( isset( $user->roles ) && is_array( $user->roles ) ) {
  12. //check for admins
  13. if ( in_array( 'administrator', $user->roles ) ) {
  14. // redirect them to the default place
  15. return $redirect_to;
  16. } else {
  17. // return home_url(); // homepage
  18. return $_SERVER['HTTP_REFERER']; // page the user is on
  19. }
  20. } else {
  21. return $redirect_to;
  22. }
  23. }
  24.  
  25. add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement