For a while now PHP-FIG has been making the PHP world better by defining standards for things like coding standards, coding styles, loggers and, importantly, autoloading. Autoloading is important because it allows us to write our code using Namespaces which makes for a much nicer folder structure and more modular classes (and packages), without having to worry about require(ing) files all the time. If you're still not with me have a look at the PSR-4 spec. Anyway, I would recommend that any PHP developer worth their salt should be using PSR-0 and PSR-4 as much as possbile. So how do you go about doing this in WordPress plugins? Well it's actually relatively simple. Let's say we have a WordPress plugin called "Turnover", with a basic folder structure that looks like: /turnover - turnover.php So the content of our main turnover.php plugin file should look like this:
Share This