Advertisement
Guest User

Untitled

a guest
May 30th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. <?php
  2.  
  3. function brg_login_redirect( $redirect_to, $request, $user ) {
  4. global $user;
  5. //if there's a user with defined roles
  6. if ( isset( $user->roles ) && is_array( $user->roles ) ) {
  7. //check if it's admin
  8. if ( in_array( 'administrator', $user->roles ) ) {
  9. //admins can go anywhere
  10. return $redirect_to;
  11. } else {
  12. //non-admins go to home
  13. return home_url();
  14. }
  15. //there's no user roles to check
  16. } else {
  17. //go home
  18. return home_url();
  19. }
  20. }
  21. add_filter( 'login_redirect', 'brg_login_redirect', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement