Skip to content

isabella232/composer-wordpress-autoloader

Repository files navigation

Composer WordPress Autoloader

Latest Version on Packagist Tests

Autoload WordPress files configured via Composer that support the Wordpress Coding Standards using alleyinteractive/wordpress-autoloader. Will load the autoloaded classes defined in your package and all autoloaded classes in your dependencies.

Installation

You can install the package via composer:

composer require alleyinteractive/composer-wordpress-autoloader

Usage

{
  "autoload": {
    "wordpress": {
      "My_Plugin_Namespace\\": "src/",
    }
  },
  "autoload-dev": {
    "wordpress": {
      "My_Plugin_Namespace\\Tests\\": "tests/",
    }
  }
}

Once added a vendor/wordpress-autoload.php file will be created. You can load that in place of vendor/autoload.php (it will load that for you) to load you WordPress and Composer dependencies.

Use Inside Packages Published to Packagist

Packages published to Packagist are required to be valid and have a composer.json that passed a composer validate. Composer does not consider wordpress to be a valid value inside of the autoload or autoload-dev property. To allow packages to register autoloading in a valid format, you can use the following format:

{
  "extra": {
    "wordpress-autoloader": {
      "autoload": {
        "My_Plugin_Namespace\\": "src/",
      },
      "autoload-dev": {
        "My_Plugin_Namespace\\Tests\\": "tests/",
      }
    }
  }
}

Automatically Injecting WordPress Autoloader

Composer WordPress Autoloader can also automatically inject the WordPress autoloader into your vendor/autoload.php file you're already loading. This is disabled by default.

{
  "extra": {
    "wordpress-autoloader": {
      "inject": true
    }
  }
}

Once enabled, you can load vendor/autoload.php like you do normally and have your WordPress files automatically loaded.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

About

Composer Autoloader for WordPress Coding Standards Classes

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%