title: How to add wordpress includes and login management to custom module?
body: <p>I am building a Wordpress site with the Constructor theme. I had to add custom coding to solve my goals. There is a module, that let's the user add children elements to his profile, that will be saved to database. (create, update, delete) This functionality is done with the following files in:</p>
  
  <pre><code>wp-content\themes\constructor\crud\
   destroy_user.php,
   get_users.php,
   save_user.php,
   show_form.php,
   update_user.php 
  </code></pre>
  
  <p>These files at the moment have no includes, they are only called from a custom coded page template. So far they work.</p>
  
  <p>Now I would like to develop this module to handle multiple users. For this I would need to know who is using the module. This I know at the custom page template, but not at the code in ex. get_users.php . For example I would like to use</p>
  
  <pre><code>$user_id = get_current_user_id();
  </code></pre>
  
  <p>in get_users.php to control the sql and redirect the user if he is not logged in. <strong>What files and how must I include, to be able to use get_current_user_id()?</strong>
  (Simply include '../../../../wp-includes/user.php' does not solve it.)</p>
  
  <p>Thanks for the help,
  Sziro</p>
  
  <p>Edit: this is wp-content\themes\constructor\crud\get_users.php</p>
  
  <pre><code>&lt;?php
  
      $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
      $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
      $offset = ($page-1)*$rows;
      $result = array();
  
      include 'conn.php';
      require('../../../../wp-blog-header.php');
      $user_id = get_current_user_id(); //This does not work. If it would be set to = 1, it would work.
  
  
      $rs = mysql_query("select count(*) from user_partner where user_id=$user_id");
      $row = mysql_fetch_row($rs);
      $result["total"] = $row[0];
      $rs = mysql_query("select * from user_partner where user_id=$user_id limit $offset,$rows");
  
      $items = array();
      while($row = mysql_fetch_object($rs)){
          array_push($items, $row);
      }
      $result["rows"] = $items;
  
      echo json_encode($result);
  
  
  ?&gt;
  </code></pre>