title: Auto redirect a user who isn't logged into the Wordpress site
body: <p>Does anyone know how to set functions.php when redirection to login page when a user isn't logged in?
  Here's my code which creates some disabilities like no preview on article page etc...</p>
  
  <pre><code>add_filter( 'pre_get_posts', 'swpm_auto_redirect_non_members' );
  function swpm_auto_redirect_non_members() {
      if( !is_admin() &amp;&amp; !SwpmMemberUtils::is_member_logged_in() &amp;&amp; !is_page( array( 'membership-login', 'membership-join' )) ) {
          wp_redirect( 'http://example.com/membership-login/' );
          exit;
      }
  }
  </code></pre>
  
  <p>It should work only when website is in service not admin mode.
  Thanks in advance.</p>