As I’ve continued to work with integration mobile applications with the WordPress REST API, there have been a few instances in which I’ve wanted to inspect, manage, or manipulate incoming REST API Requests.
There’s a number of reasons you may want to manipulate incoming WordPress REST API requests before they actually begin interacting with the core application. In my case, I needed to determine:
which endpoint is being requested,
check whether or not a specific key is being bassed,
return an error if not or proceed with further processing.
But that’s one of many different possibilities available. What I’m more interested in, at least in this article, is showing how to manipulate a request before it’s actually sent to be processed.
Over the years, I think the concept of a “drop-in” plugin has become overloaded. What once referred to a very specific type of functionality has evolved to mean a couple of things.
One of the definitions retains the original definition which is you can place specific files into the plugins directory to replace core WordPress functionality. These are not standard WordPress plugins, though. For example, you’ll likely often see files like advanced-cache.php or object-cache.php in the plugins directory. These are the original type of ‘drop-ins’ when it comes to working with WordPress.
Another definition are plugins that aren’t specifically mu-plugins and they aren’t standalone plugins either. Instead, these are pieces of functionality that can be dropped into any other plugin and add functionality. Say you have two different plugins that are used by a lot of people and you want to give them the ability to add a feature without activating a new plugin. The way in which you can do this is have them drop a file into their existing plugin.
Here’s the challenge with the second definition: When you drop functionality of into the context of another plugin, that plugin may not be the only one already running the same code.
In other words, say you have a file called acme-functionality.php that can be added to any plugin. If you drop acme-functionality.php into multiple, activated plugins then you may end up with all kinds of results none of which are ideal. And why isn’t it ideal? Because you want the code to run only once.
What’s a way to check to see if a file is already running in the context of another plugin before running it’s code?
So as I continue with the series, we’re first going to look at what’s required to implement a custom block that includes:
and an input field to help guide the ultimate output.
We’ll continue to use the customization options we’ve outlined in this post and show how we can apply them to what the user provides and how to ignore them for what we, as the developer, provide.
After that, we’ll look at adding an input to the frontend of the site as well as incorporating a SlotFill.
And though I had intentions to follow through starting at the beginning of the new year, I obviously never followed through with the series. In all of the years that I’ve been writing, sharing code, and generally participating in all things PHP, WordPress, and development, I don’t think I’ve ever simply declared bankruptcy on an actual series or even just on the consistency of blogging in general.
When working with multiple version of PHP installed via Homebrew, there’s a chance you’ll encounter error messages like this:
PHP Warning: Module 'imagick' already loaded in Unknown on line 0
PHP Warning: Version warning: Imagick was compiled against Image Magick version 1809 but version 1808 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
Granted, the version number may be different but the rest of the message will be the same. When I’ve experienced this, it’s when I’ve a set up like this:
I have multiple versions of PHP installed (anything from the earliest build in 7 up to the latest version in 8),
I swap among versions in my ~/.zshrc file depending on the project,
When I attempt to run code that’s on an older version of PHP after installing and using the newer or latest version of PHP, I see the above error.
To fix this, there are two things you can do:
Locate the version of the php.ini file for the version of PHP you’re currently using,
Update the php.ini file for the version to disable the version check on Imagick.
If you are looking for WordPress guides and unbiased reviews, I recommend checking out WPKube. They also have an exclusive deals section.
Just Getting Started with WordPress? I write a lot about WordPress development but if you're just getting started, I recommend checking out WPBeginner. They have free training videos, glossary, and more.