The Who, What, Where, When, and Why of using WordPress Hooks. We will explore examples of rolling our own to allow other developers to hook into our code.
1. 5 W's of Hookin'
Nowell VanHoesen
@NowellVanHoesen
about.me/NowellVanHoesen
2. Hookin' Overview
What are Hooks
Who hooks
Why hook
Where are they
When to hook
Examples
@NowellVanHoesen5 W's of Hookin'
3. What are hooks?
A specific place/time in WordPress code
execution to add functionality or change data.
@NowellVanHoesen5 W's of Hookin'
4. What are hooks?
A specific place/time in WordPress code
execution to add functionality or change data.
Types:
– Action: add functionality at a specific point
when an event happens or is about to
happen.
@NowellVanHoesen5 W's of Hookin'
5. What are hooks?
A specific place/time in WordPress code
execution to add functionality or change data.
Types:
– Action: add functionality at a specific point
when an event happens or is about to
happen.
– Filter: modify data before some event
( save, display )
@NowellVanHoesen5 W's of Hookin'
7. Who hooks?
Any one who wants to add custom code to
change how WordPress behaves or modify
what is output to the browser.
@NowellVanHoesen5 W's of Hookin'
8. Who hooks?
Any one who wants to add custom code to
change how WordPress behaves or modify
what is output to the browser.
Anyone who wants to allow others to build on
to their plugin or theme.
@NowellVanHoesen5 W's of Hookin'
14. Why
use hooks
● Tweak
functionality/output
to better fit your
needs
● Maintain your
customizations when
updating
create hooks
● Allow others to add
functionality
@NowellVanHoesen5 W's of Hookin'
15. Why
use hooks
● Tweak
functionality/output
to better fit your
needs
● Maintain your
customizations when
updating
create hooks
● Allow others to add
functionality
● Allow others to filter
output from your
plugin/theme
@NowellVanHoesen5 W's of Hookin'
18. Where...
can I find them
● WordPress core
● Themes
@NowellVanHoesen5 W's of Hookin'
19. Where...
can I find them
● WordPress core
● Themes
● Plugins
@NowellVanHoesen5 W's of Hookin'
20. Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
@NowellVanHoesen5 W's of Hookin'
21. Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
@NowellVanHoesen5 W's of Hookin'
22. Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
● Plugins
@NowellVanHoesen5 W's of Hookin'
23. Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
● Plugins
● WordPress core
@NowellVanHoesen5 W's of Hookin'
24. Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
● Plugins
● WordPress core
@NowellVanHoesen5 W's of Hookin'
26. How?
Actions
● add_action( t, f, p, a )
Filters
● add_filter( t, f, p, a )
@NowellVanHoesen5 W's of Hookin'
t = tag f = function p = priority a = # args
27. How?
Actions
● add_action( t, f, p, a )
● remove_action( t, f,
p, a )
Filters
● add_filter( t, f, p, a )
● remove_filter( t, f, p,
a )
@NowellVanHoesen5 W's of Hookin'
t = tag f = function p = priority a = # args
28. How?
Actions
● add_action( t, f, p, a )
● remove_action( t, f,
p, a )
● do_action( t, f, p, a )
Filters
● add_filter( t, f, p, a )
● remove_filter( t, f, p,
a )
● apply_filters( t, f, p,
a )
@NowellVanHoesen5 W's of Hookin'
t = tag f = function p = priority a = # args
29. How?
Actions
● add_action( t, f, p, a )
● remove_action( t, f,
p, a )
● do_action( t, f, p, a )
Filters
● add_filter( t, f, p, a )
● remove_filter( t, f, p,
a )
● apply_filters( t, f, p,
a )
@NowellVanHoesen5 W's of Hookin'
http://codex.wordpress.org/Plugin_API
t = tag f = function p = priority a = # args
33. Time to go live...
@NowellVanHoesen5 W's of Hookin'
34. Time to go live...
@NowellVanHoesen5 W's of Hookin'
35. Resources
@NowellVanHoesen5 W's of Hookin'
Plugin API on the codex
- http://codex.wordpress.org/Plugin_API
Drew Jaynes – Filter of the Day: Three filters a day for 365
days
- http://fotd.werdswords.com/