title: How to use functionalities of multiple files in different directories in a WordPress theme being developed using MVC architecture
body: <p>I am developing a custom theme using the child theme Astra. I am developing a very modular system i.e. as highly cohesive and loosely coupled as I can. At first, I am developing a custom signup system as it is my need for the system.
  My directory structure is like this:</p>
  <pre><code>+astra-child-theme
    -functions.php
    -sign-up.php
    -style.css
    +controller
      -signup_controller.php
    +model
      -signup_model.php
    +includes
      +CSS
      +js
        -signup_validation_frontend.js
      +additional-scripts
        -signup_validation_backend.php
  </code></pre>
  <p>The problem I am facing is I am unable to find a proper to integrate functionalities of files spread across different directories into each other.</p>
  <p>I take the data from sign-up.php, then I send it to the signup_validation_backend.php file which is achieved easily by using functions offered by WordPress - get_theme_file_uri. It is accessible as the sign-up.php is one of the core files of my theme.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form method="post" action="&lt;?php echo get_theme_file_uri('includes/additional-scripts/sign_up_validation_backend.php') ?&gt;"&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>The problem arises when I use WordPress functions in the files in sub-directories like <code>signup_validation_backend.php</code>.</p>
  <p>After validating the data I need to access the functions of <code>signup_controller.php</code> inside <code>signup_validation_backend.php</code> and functions of <code>signup_model.php</code> inside <code>signup_controller.php</code>. I tried different ways but can't seem to find a proper way of achieving the desired result.</p>
  <ol>
  <li><p>At first I did a weird thing, I included every file inside functions.php and then included <code>functions.php</code> inside every file. I thought that this way every file would be accessible to every other file as every file is included in <code>functions.php</code>. But this didn't work, even WordPress's core functions stopped working inside <code>functions.php</code>.</p>
  </li>
  <li><p>Then I tried to include wp-load.php inside <code>signup_validation_backend.php</code> by giving relative path - <code>../../../../../wp-load.php</code> and it worked. But the problem is I can include wp-load only in one file. I also tried to create another file <code>include_wp-load.php</code> in the child theme's root folder but again, when I tried to include that file in other files, it again failed.</p>
  </li>
  <li><p>I tried to include different files in each other by giving relative paths. I tried to include <code>signup_model.php</code> in <code>signup_controller.php</code> by giving relative path - <code>../model/signup_model.php</code> but it also gave a fatal error. But to my surprise <code>../../model/signup_model.php</code> worked and the <code>signup_validtion_backend.php</code> page worked and displayed the test data and all the validated data. But when I ran the main sign-up.php page, it again gave a fatal error. And this situation is completely out of my understanding. One file is working by giving the same path but the other one isn't. And nothing seems to be working to make <code>sign-up.php</code> run.</p>
  </li>
  </ol>
  <p>So I just need a proper way to include functionalities of different files stored in different directories and if possible then WordPress's core functions available in every file of my system.</p>