Bedrock, composer autoloader and wordpress

hello, if i try to autoload a dependency in composer.json and that dependency contains a worpdress function, for example add_action(), then it fails (Fatal error: Call to undefined function). Does this mean that I can’t use the composer recommended autoloading method (in composer.json) when working with wordpress?

The Composer autoloader is called before WP. So functions like add_action() have not been loaded yet. It’s worth noting that the autoloader does have more of an Object Oriented approach, meaning that generally packages have classes that you instantiate in your app.

If you have WP specific functionality you want to setup, you should probably put these in a plugin, or even a mu-plugin. You can still install these with Composer, just declare it as a WP plugin, and it will be installed to the WP folders and loaded after WP.

1 Like