TL;DR: Here’s another way to start debugging WordPress with Ray using Composer on a project-specific basis.
Last week, I wrote a brief introduction on Ray, what I like about it, and why I enjoy using it with WordPress. I also gave a brief tutorial on how to use it in your day-to-day but that was it.
Ultimately, I want to cover more about the application from a development and debugging standpoint (as I had some great feedback about it on Twitter – thanks for that!). Before doing so, though, I thought it would be more useful to start with one more tip on how to get started using it.
Namely, how to use Ray with WordPress in a Composer-based workflow.
Debugging WordPress with Ray, Part 2
The whole reason for me writing this up is two-fold:
- I like to build my WordPress plugins using Composer whenever I have the opportunity,
- I know there are others of you who enjoy doing the same and this will provide a way for you to get started doing so.
Setting Up Composer Configuration
Assuming you have the basics of your composer.json
file set up correctly, you can add this line to the require-dev
area of the file:
{ ... "require-dev": { "spatie/ray": "^1.29.0" }, "autoload": { "psr-4": { ... } } }
Next, you can run either $ composer install
or $ composer update
depending on the state of your project.
This will install Ray into the vendor
director of your plugin and you can disable the WordPress plugin discussed in the previous post.
Using Ray
To use Ray, though, you’ll need to make sure you’re using namespaces and that you’re properly including a reference to Ray’s namespace to use the application.
For example:
namespace Acme; use Spatie\Ray; define('WPINC') || die; require_once __DIR__ . '/vendor/autoload.php'; ray('Loaded...');
Obviously, this isn’t much of a plugin file but it’s enough to get you started with including it via Composer and running it via the namespace provided by the package.
More In-Depth Content?
If you’re looking for a far more in-depth series on using Ray in WordPress then I highly recommend following all of the articles in this series in conjunction with the material here.