TL;DR: Here’s an easy way to incorporate Ray into all of your WordPress projects without needing to add use at the top of your project files. Thanks to my friend Aubrey for sharing this.
You know about Ray, right? I’ve talked about it twice already:
If you’ve been using Ray in your WordPress projects and have been including it in your composer.json file, then you’ve likely set up the top of your files like this:
use WP_Post;
use WP_Term;
use Spatie\Ray;
defined('WPINC') || die;
require_once __DIR__ . '/vendor/autoload.php';
Notice that the namespace for Ray is included in this. But if this is a utility meant for printing out error messages for debugging purposes, much like we’re used to seeing with Xdebug, then why would we include it in every file? That is, why would we include a use statement for a dependency that’s not sent to production?

We don’t have to do so.
Continue reading
