Advertisement
phpface

Auto redirect to Log In page if user hasn't logged in yet

Mar 14th, 2022
1,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.30 KB | None | 0 0
  1. /**
  2.  *
  3.  * Auto redirect to Log In page if user hasn't logged in yet
  4.  *
  5.  */
  6. add_action( 'init', function(){
  7.     if( ! is_user_logged_in() && $GLOBALS['pagenow'] !== 'wp-login.php' ){
  8.         wp_redirect( add_query_arg( array(
  9.             'auto_login_required'   =>  '1'
  10.         ), wp_login_url() ) );
  11.         exit();
  12.     }
  13. }, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement