2

I'm a bit confused because I'm programming a plugin for WordPress by using composer as it's the real way to go.

So I've created a composer file inside my plugin and some other stuff. In the composer file I've added my namespace for autoloading:

"autoload": {
  "psr-4": {
    "Johnny\\Lolkick\\": [
      "includes/classes/"
    ]
  }
}

Inside my classes folder I've created now a class with the name class-main.php. I've decided to take this name because of the WordPress naming conventions.

The class by itself was named class Main {. Inside my base plugin file I've created now a new instance of my class which failed. After changing the file name to Main.php it worked.

So in result the WordPress naming convention broke the autoloading of composer. I want to know now how do you handle this problem? How should I keep the naming convention by using composer?

1
  • I'm interested in this as well. It looks like most devs either opt not to use the (recommended) WP class filename prefixes or write their own autoloader which does comply. Have you made any progress on this?
    – MikeiLL
    Mar 29, 2021 at 22:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.