Join Carrie Dils for an in-depth discussion in this video What is the Plugin API?, part of Advanced WordPress: Action and Filter Hooks.
- [Instructor] Plugins are the way that we can extend WordPress without editing the core code itself. At its most basic, a Plugin is a set of functions written in PHP that adds specific features, or services, to a WordPress site. WordPress provides the rules of engagement, so to speak, via its Plugin API. The Plugin API is made up of hooks, both action hooks and filter hooks, that let us latch onto WordPress at a specific point in run time; such as when a user logs in or someone publishes a post.
You can think of it sort of like an assembly line; except, use your imagination and pretend these boxes are webpages. The process starts at one end and moves through to completion with a series of tasks happening along the way. WordPress has built in hooks all throughout this process that let us inject our own bit of code that either adds to, removes, or modifies things at any point in the process. For instance, let's take the process of logging into the WordPress admin area. First, I'll navigate in my browser to the login screen, then I'll fill out the login form and press the login button, finally WordPress redirects me to the admin dashboard.
Now, of course there are other things happening here behind the scenes; but, as a user, that's what I see happening. Even though this is simple process, there are a ton of hooks baked into it that we can interact with. For example, instead of the slug wp-admin, there's a filter called login_url I could use to change this to something else, like, my login or whatever. As for this actual login page, there are hooks all over it that let you do things like changing out the WordPress logo for a custom logo, changing the link of where that logo points to, and many other things.
There's also a hook called login_redirect that we could use to change the login destination. In other words, instead of redirecting to the dashboard, we could use login_redirect to send the user to a settings page instead. So let's go back to the documentation here for the Plugin API. And this is where we find all the information on what action hooks and filter hooks are built into WordPress that enable us to interact with the process. We'll be referring to the codex a lot in this course. There's also the more newly designed developer reference.
We'll be taking a look at that as well. It's a little different from the codex in terms of how the information is presented; like here, we have hooks that are new in the latest version of WordPress. This takes a little more knowing what you're researching for in order to use it, but if we click through any one of these here, you can see that the design and color coding is a little easier on the eye than the codex design; you may find that easier to use. So that's the Plugin API in a nutshell. It's the instructions WordPress gives us to let us interact with and customize WordPress.
- Actions and filters explained
- Identifying available hooks and filters
- Looking at load order
- Understanding callback functions
- Creating custom hooks
- Using third-party hooks
- Building a new WordPress plugin with filters and actions