title: Creating a function to logout a WordPress user?
body: <p>I'm trying to create a function to logout WordPress users after a period of inactivity. The timed element is working as it should and redirecting users after a set period of time. </p>
  
  <p>The problem is that once the PHP script is loaded (in code sample), I run into the following error: <strong>Fatal error: Call to undefined function wp_logout() in /var/www/html/wp-content/plugins/ion-wp-login-timeout/scripts/timed-logout.php on line 5</strong></p>
  
  <p>All the reference material I read tells me that wp_logout() should log out the user but instead there are errors. I have tried several methods, including adding an action. I do not want to redirect the user to a login screen. </p>
  
  <p>Sample of code is below. The echo statements are in place purely for testing. Any help would be much appreciated. </p>
  
  <pre><code>&lt;?php
  
      function logout_this_session() {
          //Logout Now
          wp_logout();
          wp_die();
      }
  
      echo 'This will be the logout script&lt;br/&gt;&lt;br/&gt;';
  
      $last_page = $_SERVER['HTTP_REFERER'];
      echo 'You came from: ' . $last_page;
  
      logout_this_session();
  
      header( 'Location: ' . $last_page );
  
  ?&gt;
  </code></pre>