Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In this video we walk through how to find out more about filters and actions using Google, the WordPress Codex and the Developer Site.
Codex Reference
- Plugin API/Filter Reference in the Codex
- Plugin API/Action Reference in the Codex
- Developer Code Reference
-
0:01
The Word Press code X is a great place to see a comprehensive list of
-
0:05
all the Word Press actions and filters.
-
0:08
So let's jump into the browser and
-
0:10
see what we're working with in terms of native Word Press hooks.
-
0:15
One of the simplest ways to get a full list of all of
-
0:18
the Word Press filters is simply to search Google for Word Press, filters.
-
0:24
You may even see a customized result box come up, but the link that you're
-
0:28
looking for should have plug in API, and then filter reference.
-
0:34
This page starts off with some general information about the plug in API and
-
0:39
writing a plug in,
-
0:40
as well as a link to a full database output of all the hooks available.
-
0:46
If we come down the page a little bit, we could see that the filters are broken up
-
0:51
into different sections that relate to post filters, comment-related filters,
-
0:56
categories, links, date and time and author, as well as a number of other ones.
-
1:03
What you'll notice as you begin to look through this list,
-
1:06
is that a lot of filters are applied to template tags that you
-
1:09
would recognize from theme development.
-
1:12
We can see that some filters apply when we're reading from the database and
-
1:17
then some filters are going to apply when we're writing to the database, again,
-
1:22
filters work with data that's either being pulled from the database and
-
1:25
before it's displayed to the browser or possibly the other way around.
-
1:31
It's important that after this video you take the time to really scroll through
-
1:35
this page and look at some of these filters that are available.
-
1:39
Some of them, you may not understand or know what they do,
-
1:42
however, some of them, like excerpt and things related to getting pages,
-
1:46
should sort of make sense from other work that you've done in WordPress.
-
1:50
[BLANK_AUDIO]
-
1:57
As we scroll through the page, we'll see the different sections where we
-
2:01
can see filters that apply to different things.
-
2:03
For example, in this case, the comment filters.
-
2:08
We have filters that relate to the categories, link filters,
-
2:14
date and time filters, author filters,
-
2:17
as well as ones that relate to general information about the site-
-
2:23
[BLANK_AUDIO]
-
2:26
general text filters and then some helpful ones for the admin side as well.
-
2:33
Like I said, it's important that you take the time to at
-
2:35
least read through this list and try to get an idea of what makes sense to you and
-
2:40
what you see that is familiar.
-
2:43
Filters again can let you take this data that you
-
2:46
would commonly be exporting out or using in your template for
-
2:49
example, and let you apply your own code in customization quickly from
-
2:54
something like the functions.php file which we'll look at later.
-
2:59
If we wanted to look at all of the actions that are available,
-
3:02
we could simple search for WordPress actions, see a similar result, and
-
3:07
look for the Plugin API Action Reference URL.
-
3:12
Now actions are a little bit different in that instead of allowing us to
-
3:16
manipulate data before or after it comes from the database or the browser.
-
3:21
In this case, we're getting access to run our code at a certain point while
-
3:25
WordPress is building out the actual page or the admin area.
-
3:30
So if we take a look at how these are organized, we could see that it
-
3:33
gives us actions that are run during a typical request of building out a page,
-
3:38
as well as actions that are run when building out an admin page.
-
3:43
It then has similar sections to filters, except instead of manipulating the data,
-
3:48
we'd be running our own actions or code at those different points.
-
3:52
As we scroll down here, we can see from a very beginning all of the actions that
-
3:57
take place as WordPress is firing up, figuring out what's going on,
-
4:02
running its initialization, building out things like what side bar's being used,
-
4:08
the admin bar that's displaying, and then we can see that we reach a point at
-
4:13
WP loaded where word press is fully loaded and then it's going to begin echoing out
-
4:18
the actual page sending headers, pulling together the WP object, getting
-
4:26
the header in queuing scripts which you should recognize from loading your CSS,
-
4:30
the wp_head output, then getting into the actual post and the loop,
-
4:39
outputting sidebars, the footer, and then finally, the very end of the process.
-
4:46
It then runs through the actions that would happen when building out an admin
-
4:50
page, which can be slightly different, although you'll see some of the same
-
4:54
things, however, in this case we'll see more hooks that have admin in them, and
-
4:59
pertain more to setting up what's needed for authentication and access and
-
5:04
building out admin pages and viewing content that way.
-
5:08
However, at a certain point it will begin to pull in poster other data that it
-
5:12
needs to display.
-
5:14
The rest of the page goes through all of the different actions that you
-
5:17
would find in relation to these different categories or sections.
-
5:21
For example, we could see when a post is being edited, when it's being deleted,
-
5:26
when it's being published or saved, and we could run our own code at those points.
-
5:31
Also getting access to whatever data WordPress has at that point.
-
5:37
Going through comments, the feed, templates, admin
-
5:44
actions, and then finally some advanced ones at the end.
-
5:51
As I said before with filters, it's important that you take a few minutes, or
-
5:55
longer if it interests you, and go through and look at each one of these.
-
6:01
If you see one that you're interested in but it's in red, that means that
-
6:05
there's currently no page in the Codex that gives information about it.
-
6:10
However, at the time of writing, WordPress is working on a new code reference and
-
6:15
you can take whatever it is that you're looking for
-
6:18
here, come over to the new code reference,
-
6:21
[BLANK_AUDIO]
-
6:24
and search for it there.
-
6:27
Find that it's the hook that you're looking for, and
-
6:32
then click through to find out more information.
-
6:34
We can see that here, it's telling us that this hook has been deprecated and
-
6:38
we shouldn't be using it, and we could look for this one instead.
-
6:44
At the point of writing this, the developer resources at developer.org
-
6:52
does have a few more hooks documented, in fact quite a few more hooks documented.
-
6:57
However, it doesn't currently have the same generic pages that let us easily see
-
7:01
the different categories and groupings of different actions and filters.
-
7:07
For that reason, the codex action reference and filter reference
-
7:13
is still a good general resource, however, if you come to things
-
7:18
like widgets init for example we can come over to the new code reference,
-
7:25
[BLANK_AUDIO]
-
7:26
search for widgets in it and find out more information about it here.
-
7:36
So for the time being you may need to bounce between these two in order to
-
7:40
find out more information on all of the different actions and
-
7:43
filters, however, this is a great start in resource for finding more about these.
-
7:50
In then next view videos, we're going to look at some other ways in
-
7:53
which you could also access this same information in some different formats.
You need to sign up for Treehouse in order to download course files.
Sign up