Guest Post by WordCamp Albuquerque speaker Bryce Corkins
For any WordPress project, it can seem like there are a dozen methods to accomplish almost everything—and there are! Unfortunately, there are a lot of wrong ways to write your code, and only a few right ones. (Or a lot of right ones, depending on who you talk to). In this talk, we’ll be looking specifically at the WordPress Hook, Action, and Filter process: what it is, how it works, and how it can make your life a lot easier.
Hooks are functions provided by WordPress to allow your theme or plugin to “hook into” the rest of WordPress. There are two types of hooks: actions and filters (and they are different). Actions allow you to specify a custom function to be executed at a certain point during WordPress’ execution, or when a specific event occurs. For example, you could execute a function whenever a post is published, whenever a new user registers, after the admin page has finished loading, or at many more points (there are, as of WordPress 3.4, 587 built in actions).
Filters, on the other hand, are used to “filter” text as it’s moved between the user interface and the database. For example, you could change the length of a post excerpt, create a profanity filter, highlight search terms in your search results, and (again) much more.
In this talk, we’ll go over ways in which hooks, actions, and filters can make your life as a developer a lot easier. We’ll go through some common use case scenarios, talk about how to selectively disable parts of plugins and themes without modifying their source code, and how to troubleshoot currently running hooks.
A basic understanding of PHP and WordPress functionality is recommended for this presentation, but all are welcome.