Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. // Taken from the Codex
  2. // https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
  3. /**
  4.  * Redirect user after successful login.
  5.  *
  6.  * @param string $redirect_to URL to redirect to.
  7.  * @param string $request URL the user is coming from.
  8.  * @param object $user Logged user's data.
  9.  * @return string
  10.  */
  11. function my_login_redirect( $redirect_to, $request, $user ) {
  12.     //is there a user to check?
  13.     global $user;
  14.     if ( isset( $user->roles ) && is_array( $user->roles ) ) {
  15.         //check for admins
  16.         if ( in_array( 'administrator', $user->roles ) ) {
  17.             // redirect them to the default place
  18.             return $redirect_to;
  19.         } else {
  20.             return home_url();
  21.         }
  22.     } else {
  23.         return $redirect_to;
  24.     }
  25. }
  26.  
  27. add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
  28.  
  29.  
  30. function redirect_admin(){
  31.     if(!current_user_can('edit_posts')) {
  32.         wp_redirect(home_url());
  33.     exit;
  34.     }
  35. }
  36. add_action('admin_init', 'redirect_admin');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement