title: PHP - PSR-4 autoload in WordPress Plugin namespace
body: <p>I know many similar questions have been asked but I have followed every guide I can find and it still is not working for me. I don't know if it has to do with it being a WordPress plugin, but the autoloader is not finding my classes.</p>
  
  <p>In my plugin, I am running into a lot of Class Name collisions. I know I could prefix every class with the name of the plugin but I feel like it would be easier/cleaner to have the entire project under a specific namespace. I am still somewhat new to PHP so I may be thinking about this all wrong but I think it should work. I understand there are other ways to make this work but I would like to understand why this isn't working. Thank you for any input or help you can offer!</p>
  
  <p>The error I am getting:</p>
  
  <pre><code>Fatal error: Class 'DistinguishedSites\Inc\Base\Activate' not found in /home/pluginte/public_html/wp-content/plugins/distinguished-sites/distinguished-sites-plugin.php on line 47
  </code></pre>
  
  <p>Simplified directory structure:</p>
  
  <pre><code>/distinguished-sites
    - distinguished-sites-plugin.php
    - composer.json
    - /vendor
        - *All vendor files*
    - /inc
        - /Base
            - Activate.php
    *etc...*
  </code></pre>
  
  <p>Activate.php file:</p>
  
  <pre><code>&lt;?php
  /**
   * @package DistinguishedSites
   */
  namespace DistinguishedSites\Inc\Base;
  
  class Activate
  {
  
      public static function activate() {
          $db = new DatabaseApi();
          $filter = new PostFilter;
  
          $db-&gt;createTable(); 
  
          $results = $filter-&gt;filterPosts();
  
          flush_rewrite_rules();
      }
  }
  </code></pre>
  
  <p>I am trying to use the Activate class in my distinguished-sites-plugin.php file:</p>
  
  <pre><code>&lt;?php
  /**
   * @package DistinguishedSites
   */
  
  use \DistinguishedSites\Inc\Base\Activate;
  
  defined( 'ABSPATH' ) or die( 'Hey, what are you doing here? You silly human!' );
  
  // Require autoload file.
  if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
      require_once dirname( __FILE__ ) . '/vendor/autoload.php';
  }
  
  define( 'PLUGIN_PATH', plugin_dir_path( __FILE__ ));
  define( 'PLUGIN_URL', plugin_dir_url( __FILE__ ));
  define( 'PLUGIN', plugin_basename( __FILE__ ));
  
  // Runs on plugin activation.
  function activate_distinguished_sites_plugin() {
      Activate::activate();
  }
  register_activation_hook( __FILE__, 'activate_distinguished_sites_plugin');
  
  // Runs of plugin deactivation.
  function deactivate_distinguished_sites_plugin() {
      //Deactivate::deactivate();
  }
  register_deactivation_hook( __FILE__, 'deactivate_distinguished_sites_plugin');
  
  
  // Initialize core classes of the plugin. 
  if ( class_exists( 'DistinguishedSites\Init' ) ) {
      Init::register_services();
  }
  </code></pre>
  
  <p>composer.json file: </p>
  
  <pre><code>{
      "name": "sno/distinguished-sites",
      "description": "Distinguished sites badge submission plugin.",
      "type": "project",
      "license": "GPL",
      "authors": [
          {
              "name": "noah",
              "email": "noah.seichter@snosites.com"
          }
      ],
      "minimum-stability": "dev",
      "require": {},
      "autoload": {
          "psr-4": {
              "DistinguishedSites\\": "."
          }
      }
  }
  </code></pre>
  
  <p>autoload_psr4.php file:</p>
  
  <pre><code>&lt;?php
  
  // autoload_psr4.php @generated by Composer
  
  $vendorDir = dirname(dirname(__FILE__));
  $baseDir = dirname($vendorDir);
  
  return array(
      'DistinguishedSites\\' =&gt; array($baseDir . '/'),
  );
  </code></pre>