title: Wordpress oop plugin developing, can't find function
body: <p>So, I am not completely new to developing plugins in WordPress but this is something I've been bumping onto.</p>
  
  <p>I am making a plugin using the Object Oriented style. This, however, is completely new to me.</p>
  
  <p>I am trying to make an admin menu icon to display in the backend. This is quite easy when just using function. But somehow, in OOP, I get this error:</p>
  
  <pre><code>Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'ssp_build_hook' not found or invalid function name in /home/example/domains/example.com/public_html/test/wp-includes/plugin.php on line 503
  </code></pre>
  
  <p>Now, I have no clue how to fix this. I have thought about WordPress not fully loaded when trying to call that function.</p>
  
  <p>This is my main file, <strong>test-plugin.php:</strong></p>
  
  <pre><code>&lt;?php
      namespace SSP;
  
      spl_autoload_register(__NAMESPACE__ . '\\autoload');
  
      function autoload($cls)
      {
  
          $cls = ltrim($cls, '\\');
          if(strpos($cls, __NAMESPACE__) !== 0)
              return;
  
          $cls = str_replace(__NAMESPACE__, '', $cls);
  
          $path = plugin_dir_path(__FILE__) . 'inc' . str_replace('\\', DIRECTORY_SEPARATOR, $cls) . '.php';
  
          require_once($path);
  
      }
  
      class CSSP_Prepare {
  
          function __construct() {
  
              global $wpdb;
              $this-&gt;tablename = $wpdb-&gt;prefix . 'example_table';
              $this-&gt;fssp_register_hooks();
  
          }
  
          function fssp_register_hooks() {
  
              register_activation_hook(__FILE__, array(&amp;$this, 'fssp_activate'));
              register_deactivation_hook(__FILE__, array(&amp;$this, 'fssp_deactivate'));
              //register_uninstall_hook(__FILE__, array(&amp;$this, 'fssp_uninstall'));
  
          }
  
          function fssp_activate($wpdb) {
              global $wpdb;
              if($wpdb-&gt;get_var("SHOW TABLES LIKE '" . $this-&gt;tablename . "'") != $this-&gt;tablename) {
  
                  $this-&gt;sql = 'CREATE TABLE ' . $this-&gt;tablename . ' (id bigint(21) NOT NULL AUTO_INCREMENT, text text, UNIQUE KEY id (id)) ';
                  require_once(ABSPATH.'wp-admin/includes/upgrade.php');
                  dbDelta( $this-&gt;sql );
  
              }
  
          }
  
          function fssp_deactivate() {
  
  
  
          }
  
          function fssp_uninstall() {
  
              $this-&gt;sql = 'DROP TABLE ' . $this-&gt;tablename . '';
              require_once(ABSPATH.'wp-admin/includes/upgrade.php');
              dbDelta( $this-&gt;sql );
  
          }
  
      }
  
      new CSSP_Prepare();
  
  
      class CSSP_Construct {
  
          function __construct() {
  
              $this-&gt;build = new CBuild();
  
  
  
          }
  
          function fssp_construct() {
  
              $this-&gt;build-&gt;ssp_init();
  
          }
      }
  
      $page_constructor = new CSSP_Construct();
      $page_constructor-&gt;fssp_construct();
  ?&gt;
  </code></pre>
  
  <p>So as you can see, I am trying to call <code>$this-&gt;build-&gt;ssp_init()</code> from the <code>CBuild</code> class.</p>
  
  <p>CBuild code is as follows <strong>CBuild.php:</strong></p>
  
  <pre><code>&lt;?php
  
  namespace SSP;
  
  class CBuild {
  
      function __construct() {
  
          require_once( ABSPATH . '/wp-load.php' );
  
      }
  
      function ssp_init() {
  
          add_action('wp_loaded', 'ssp_build_hook');
  
      }
  
      public function ssp_build_hook() {
  
          add_action('admin_menu', 'ssp_buildpage_hooks');
  
      }
  
      function ssp_buildpage_hooks() {
  
          add_menu_page('SSP Options', 'SSP Options', 'manage_options', 'example_plugin_options', 'ssp_build_options_page', 'dashicons-art');
          add_menu_page('SSP Orders', 'SSP Orders', 'manage_options', 'example_plugin_orders', 'ssp_build_orders_page', 'dashicons-cart');
  
      }
  
      function ssp_build_options_page() {
  
          ?&gt;
  
          &lt;div class="wrapper"&gt;
              &lt;form action="options.php" method="post"&gt;
                  &lt;?php settings_fields('ssp_options'); ?&gt;
                  &lt;?php do_settings_sections('ssp_options_input'); ?&gt;
                  &lt;?php submit_button(); ?&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
          &lt;?php
  
      }
  
      function ssp_build_orders_page() {
  
          ?&gt;
  
          &lt;div class="wrapper"&gt;
              &lt;form action="options.php" method="post"&gt;
                  &lt;?php settings_fields('ssp_orders'); ?&gt;
                  &lt;?php do_settings_sections('ssp_orders_input'); ?&gt;
                  &lt;?php submit_button(); ?&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
          &lt;?php
  
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>So you can see, I am calling <code>$this-&gt;build-&gt;ssp_init();</code> in <code>test-plugin.php</code> and this function is located in <code>CBuild.php</code>. <br>This function contains a WordPress action hook, <br><code>add_action('wp_loaded', 'ssp_build_hook');</code>. 
  But it can't find <code>ssp_build_hook</code>.</p>
  
  <p>So my question is, why can't it find <code>ssp_build_hook</code>? <br>
  Any advice, tutorials, coding improvements or question improvements would be greatly appreciated!</p>