SlideShare a Scribd company logo
1 of 24
Download to read offline
build create W O R D C A M P G R A N D R A P I D S
W O R D P R E S S H O O K S
I N T R O D U C T I O N T O
build create W O R D C A M P G R A N D R A P I D S
build create W O R D C A M P C H I C A G O
H I .
Designer, developer,
marketer, shit-talker, etc.
Co-owner build/create studios
@buildcreate 

@wilsonography

buildcreate.com
I ’ M I A N , N I C E T O M E E T Y O U .
build create W O R D C A M P G R A N D R A P I D S
M Y S E L F I S H G O A L S F O R Y O U
I want you to walk away from this feeling a little less
hacky, a little more informed, and most of all inspired.
I want you to have an “Ah ha!” moment, where suddenly
your understanding of WordPress becomes that much
clearer, and you can’t wait to get out of this room to try
out your new knowledge.
Here goes nothing…
build create W O R D C A M P G R A N D R A P I D S
L E T ’ S TA L K A B O U T H O O K S
“Hooks enable us to literally hook into parts of the
WordPress page lifecycle to retrieve, insert, or modify
data, or they allow us to take certain actions behind the
scenes.”

- T O M M C FA R L I N @ T U T S P L U S
build create W O R D C A M P G R A N D R A P I D S
A W O R L D W I T H O U T H O O K S
build create W O R D C A M P C H I C A G O
I T ’ S P R E T T Y D A M N H A C K Y
• Including extra PHP files for ajax
requests
• Hacking into plugins to change
display/functionality
• Hacking *gasp* WP core files
• Hacking theme files (when you
should be using a child theme)
• Hackity hack hack hack.
build create W O R D C A M P C H I C A G O
F I LT E R S
• Applying changes to
content/data
• Uses functions:
• apply_filters()

This is the hook.
• add_filter()

This is what you use to tie into
the hook.
A C T I O N S
• Hooks your functions into
an action in WP
• Uses functions:
• do_action()

This is the hook.
• add_action()

This is what you use to tie into
the hook.
build create W O R D C A M P G R A N D R A P I D S
Filters and Actions are nearly the same thing in WordPress,
almost identical syntax, capabilities, and limitations.
The difference is how you use them.
build create W O R D C A M P C H I C A G O
F I LT E R S
• Change something you’re
pulling out of WP- the
content, a media file, etc.
• Change something you’re
putting into the WP database
A C T I O N S
• Tying into existing WP processes,
like sending email, saving a post,
saving a comment, etc.
• Add an action to your plugin/
theme to allow other developers
to manipulate it without hacking
W H E N S H O U L D W E U S E T H E S E
L O V E LY H O O K S ?
build create W O R D C A M P C H I C A G O
A K A A L L T H E D A M N
T I M E . I T ’ S M A G I C .
build create W O R D C A M P G R A N D R A P I D S
S O , L E T S M A K E S O M E M A G I C …
build create W O R D C A M P G R A N D R A P I D S
A N AT O M Y O F A H O O K
add_filter( $hook, $function_to_add, $priority, $accepted_args );
The name of the
filter to hook into
Your function you
want to run when
the filter is applied
Lower numbers =
earlier execution
of your filter
Any additional
arguments you
want to pass to
the function
add_action( $hook, $function_to_add, $priority, $accepted_args );
build create W O R D C A M P G R A N D R A P I D S
S O M E N I T T Y G R I T T Y N O T E S
• Usually a filter comes with one argument by default- the content that you’re going to be
modifying. Some filters accept additional arguments as specified in the matching
“apply_filter” call. Make sure you’re aware of these when you use the filter.
• Though you can pass all kinds of arguments into your filter function, the only thing you
get back is the value of what you’re filtering. So for example if you’re using
‘the_content’ filter, and you have your function accept the post ID as well as the default
content argument, all you can safely return at the end of your function is the content.
• Actions don’t return any data, only true. Always true. Deal with it.
• Actions also allow you to pass “all” as the hook name to tie into every hook. Yikes.
• You can pass a class method like so: array( 'My_Class', ‘my_class_method’ ).

This is especially useful in plugin development when ofttimes your plugin has several
class methods.
build create W O R D C A M P G R A N D R A P I D S
U P N E X T: A S U P E R D U P E R S I M P L E E X A M P L E
build create W O R D C A M P G R A N D R A P I D S
add_filter(‘the_content’, ‘my_filter_function’, 10);
function my_filter_function($content) {
$output = '<div>'.$content.'</div>';
return $output;
}
build create W O R D C A M P G R A N D R A P I D S
add_filter(‘the_content’, ‘my_filter_function’, 10);
function my_filter_function($content) {
$output = '<div>'.$content.'</div>';
return $output;
}
This variable comes
through from the
matching apply_filter()
The name of the
filter to hook into
Your function you want to
run when the filter is applied
Lower numbers = earlier
execution of your filter
build create W O R D C A M P G R A N D R A P I D S
D E F I N I N G Y O U R H O O K S
apply_filter( $tag, $value, $arg );
The name of the
filter to hook into
The value you
want to modify
with the filter
One or more additional arguments
passed to the filter function
do_action( $tag, $arg);
See? The only difference is that we aren’t
passing a value to modify.
build create W O R D C A M P G R A N D R A P I D S
E X A M P L E H O O K S
• save_post - Action: runs whenever a post or page is created/updated. Useful for saving custom
meta information.
• add_meta_boxes - Action: used to add meta boxes to the WordPress edit screen. You’d then
probably wind up using the save_post action to validate the data before saving.
• wp_enqueue_scripts - Action: used to add styles and scripts to the front end. Used a lot in themes
and plugins. There’s also an admin and login version for adding styles and scripts to those areas.
• the_content, the_title, etc - Filter: used to modify the content and title respectively. There are also
filters to modify these in the editor on the backend of WordPress.
• wp_authenticate_user - Filter: used to tie into the authentication process and run your own
authentication function on the user’s login form submission.
• body_class - Filter: say you want to add some classes to the body based on various conditions
(assuming you’re using the body_class function in your template), you would use this hook in your
functions.php to handle that.
build create W O R D C A M P G R A N D R A P I D S
The best way to learn is to look at other people’s code and in the
WordPress Codex. See how they use it, how it comes together,
and of course try it yourself!
Experiment!
build create W O R D C A M P G R A N D R A P I D S
M E O W W E ’ R E TA L K I N !
build create W O R D C A M P C H I C A G O
Where does all of this
fit into the WP loading
process?
L E T S G E T T E C H N I C A L
build create W O R D C A M P C H I C A G O
N O W Y O U ’ R E T H I N K I N G W I T H H O O K S
• Work WITH plugins as the author
intended instead of hacking them!
• GTFO WP core files!
• Build better themes, child themes,
and plugins!
• ????
• Profit!
build create W O R D C A M P G R A N D R A P I D S
T H A N K S F O R C O M I N G !
• http://codex.wordpress.org/Plugin_API/Action_Reference
• http://code.tutsplus.com/articles/the-beginners-guide-to-
wordpress-actions-and-filters--wp-27373
• http://www.zell-weekeat.com/wordpress-actions-and-filters/
• http://codex.wordpress.org/Plugin_API/Filter_Reference
R E S O U R C E S
build create W O R D C A M P C H I C A G O

More Related Content

Recently uploaded

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607dollysharma2066
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts servicevipmodelshub1
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 

Recently uploaded (20)

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
FULL ENJOY Call Girls In Mayur Vihar Delhi Contact Us 8377087607
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Alwarpet Phone 🍆 8250192130 👅 celebrity escorts service
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Introduction to WordPress Hooks

  • 1. build create W O R D C A M P G R A N D R A P I D S W O R D P R E S S H O O K S I N T R O D U C T I O N T O build create W O R D C A M P G R A N D R A P I D S
  • 2. build create W O R D C A M P C H I C A G O H I . Designer, developer, marketer, shit-talker, etc. Co-owner build/create studios @buildcreate 
 @wilsonography
 buildcreate.com I ’ M I A N , N I C E T O M E E T Y O U .
  • 3. build create W O R D C A M P G R A N D R A P I D S M Y S E L F I S H G O A L S F O R Y O U I want you to walk away from this feeling a little less hacky, a little more informed, and most of all inspired. I want you to have an “Ah ha!” moment, where suddenly your understanding of WordPress becomes that much clearer, and you can’t wait to get out of this room to try out your new knowledge. Here goes nothing…
  • 4. build create W O R D C A M P G R A N D R A P I D S L E T ’ S TA L K A B O U T H O O K S “Hooks enable us to literally hook into parts of the WordPress page lifecycle to retrieve, insert, or modify data, or they allow us to take certain actions behind the scenes.”
 - T O M M C FA R L I N @ T U T S P L U S
  • 5. build create W O R D C A M P G R A N D R A P I D S A W O R L D W I T H O U T H O O K S
  • 6. build create W O R D C A M P C H I C A G O I T ’ S P R E T T Y D A M N H A C K Y • Including extra PHP files for ajax requests • Hacking into plugins to change display/functionality • Hacking *gasp* WP core files • Hacking theme files (when you should be using a child theme) • Hackity hack hack hack.
  • 7. build create W O R D C A M P C H I C A G O F I LT E R S • Applying changes to content/data • Uses functions: • apply_filters()
 This is the hook. • add_filter()
 This is what you use to tie into the hook. A C T I O N S • Hooks your functions into an action in WP • Uses functions: • do_action()
 This is the hook. • add_action()
 This is what you use to tie into the hook.
  • 8. build create W O R D C A M P G R A N D R A P I D S Filters and Actions are nearly the same thing in WordPress, almost identical syntax, capabilities, and limitations. The difference is how you use them.
  • 9. build create W O R D C A M P C H I C A G O F I LT E R S • Change something you’re pulling out of WP- the content, a media file, etc. • Change something you’re putting into the WP database A C T I O N S • Tying into existing WP processes, like sending email, saving a post, saving a comment, etc. • Add an action to your plugin/ theme to allow other developers to manipulate it without hacking W H E N S H O U L D W E U S E T H E S E L O V E LY H O O K S ?
  • 10. build create W O R D C A M P C H I C A G O A K A A L L T H E D A M N T I M E . I T ’ S M A G I C .
  • 11. build create W O R D C A M P G R A N D R A P I D S S O , L E T S M A K E S O M E M A G I C …
  • 12. build create W O R D C A M P G R A N D R A P I D S A N AT O M Y O F A H O O K add_filter( $hook, $function_to_add, $priority, $accepted_args ); The name of the filter to hook into Your function you want to run when the filter is applied Lower numbers = earlier execution of your filter Any additional arguments you want to pass to the function add_action( $hook, $function_to_add, $priority, $accepted_args );
  • 13. build create W O R D C A M P G R A N D R A P I D S S O M E N I T T Y G R I T T Y N O T E S • Usually a filter comes with one argument by default- the content that you’re going to be modifying. Some filters accept additional arguments as specified in the matching “apply_filter” call. Make sure you’re aware of these when you use the filter. • Though you can pass all kinds of arguments into your filter function, the only thing you get back is the value of what you’re filtering. So for example if you’re using ‘the_content’ filter, and you have your function accept the post ID as well as the default content argument, all you can safely return at the end of your function is the content. • Actions don’t return any data, only true. Always true. Deal with it. • Actions also allow you to pass “all” as the hook name to tie into every hook. Yikes. • You can pass a class method like so: array( 'My_Class', ‘my_class_method’ ).
 This is especially useful in plugin development when ofttimes your plugin has several class methods.
  • 14. build create W O R D C A M P G R A N D R A P I D S U P N E X T: A S U P E R D U P E R S I M P L E E X A M P L E
  • 15. build create W O R D C A M P G R A N D R A P I D S add_filter(‘the_content’, ‘my_filter_function’, 10); function my_filter_function($content) { $output = '<div>'.$content.'</div>'; return $output; }
  • 16. build create W O R D C A M P G R A N D R A P I D S add_filter(‘the_content’, ‘my_filter_function’, 10); function my_filter_function($content) { $output = '<div>'.$content.'</div>'; return $output; } This variable comes through from the matching apply_filter() The name of the filter to hook into Your function you want to run when the filter is applied Lower numbers = earlier execution of your filter
  • 17. build create W O R D C A M P G R A N D R A P I D S D E F I N I N G Y O U R H O O K S apply_filter( $tag, $value, $arg ); The name of the filter to hook into The value you want to modify with the filter One or more additional arguments passed to the filter function do_action( $tag, $arg); See? The only difference is that we aren’t passing a value to modify.
  • 18. build create W O R D C A M P G R A N D R A P I D S E X A M P L E H O O K S • save_post - Action: runs whenever a post or page is created/updated. Useful for saving custom meta information. • add_meta_boxes - Action: used to add meta boxes to the WordPress edit screen. You’d then probably wind up using the save_post action to validate the data before saving. • wp_enqueue_scripts - Action: used to add styles and scripts to the front end. Used a lot in themes and plugins. There’s also an admin and login version for adding styles and scripts to those areas. • the_content, the_title, etc - Filter: used to modify the content and title respectively. There are also filters to modify these in the editor on the backend of WordPress. • wp_authenticate_user - Filter: used to tie into the authentication process and run your own authentication function on the user’s login form submission. • body_class - Filter: say you want to add some classes to the body based on various conditions (assuming you’re using the body_class function in your template), you would use this hook in your functions.php to handle that.
  • 19. build create W O R D C A M P G R A N D R A P I D S The best way to learn is to look at other people’s code and in the WordPress Codex. See how they use it, how it comes together, and of course try it yourself! Experiment!
  • 20. build create W O R D C A M P G R A N D R A P I D S M E O W W E ’ R E TA L K I N !
  • 21. build create W O R D C A M P C H I C A G O Where does all of this fit into the WP loading process? L E T S G E T T E C H N I C A L
  • 22. build create W O R D C A M P C H I C A G O N O W Y O U ’ R E T H I N K I N G W I T H H O O K S • Work WITH plugins as the author intended instead of hacking them! • GTFO WP core files! • Build better themes, child themes, and plugins! • ???? • Profit!
  • 23. build create W O R D C A M P G R A N D R A P I D S T H A N K S F O R C O M I N G !
  • 24. • http://codex.wordpress.org/Plugin_API/Action_Reference • http://code.tutsplus.com/articles/the-beginners-guide-to- wordpress-actions-and-filters--wp-27373 • http://www.zell-weekeat.com/wordpress-actions-and-filters/ • http://codex.wordpress.org/Plugin_API/Filter_Reference R E S O U R C E S build create W O R D C A M P C H I C A G O