Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
As you know, hooks are what make plugins work. There are two basic kinds of hooks: actions and filters. Each of them serve a different purpose. Actions are performing all kinds of tasks in WordPress processing. Filters are specifically for filtering text, either before it could send to a web page or before it can save to the database. We are going to talk about these hooks and how you can register and use them in your custom plugins. So first of all, filters are how we parse text. So you can see here in the plugin API at the codex.wordpress.org, there are some functions that relate specifically to filters.
The key ones are going to be has_filter, which can determine if a filter exists, add_filter which we'll used to add a new filter, and remove_filter if you ever want remove one of your existing filters. There is different categories on filters, and you can find them in the filter reference. It's in the plugin API, in a folder called Filter_Reference, and this has a list of all kinds of filters. You can see Database Reads and Writes for the Post and Page attachment, Comment and Trackbacks, Categories, Links, Date and Time, Author and User, basically all of the different places in WordPress where they are accessing some kind of textual data.
So anytime you want to make changes to a text, either before you save or before you send it to a web page, this is where you can do it. Actions on the other hand, are where we perform some specific task. When something is happening, when a comment is being submitted, or when a menu is being created, all of these things are actions. So actions function a little differently because they don't necessarily have to do with text specifically. They usually have to do with some sort of function that's going on. But the way they behave is very much the same as filters.
So the functions are quite similar; has_action will allow to determine if one exists, add_ action will allow you to essentially hook into that action, and remove_action will also allow you to remove it. Just like with filters, there is a reference at the codex under Action_Reference, in the plugin API. Again, you can see this has broken down by the different types of places where these actions occur. A typical request, you can see, there is a number of different action hooks that takes place in the request.
Actions, on the other hand, are hooks that are called when something happens in WordPress: a post is saved, an admin menu has generated, the footers is being created, and all that kind of stuff. We can then create our own functions, set them to these filters and actions, and bam: we've got our plugins.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98470 Viewers
61 Video lessons · 85754 Viewers
71 Video lessons · 69656 Viewers
56 Video lessons · 101986 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.