SlideShare une entreprise Scribd logo
1  sur  35
5 W's of Hookin'
Nowell VanHoesen
@NowellVanHoesen
about.me/NowellVanHoesen
Hookin' Overview
What are Hooks
Who hooks
Why hook
Where are they
When to hook
Examples
@NowellVanHoesen5 W's of Hookin'
What are hooks?
A specific place/time in WordPress code
execution to add functionality or change data.
@NowellVanHoesen5 W's of Hookin'
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'
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'
Who hooks?
@NowellVanHoesen5 W's of Hookin'
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'
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'
Why
@NowellVanHoesen5 W's of Hookin'
Why
use hooks
@NowellVanHoesen5 W's of Hookin'
Why
use hooks
● Tweak
functionality/output
to better fit your
needs
@NowellVanHoesen5 W's of Hookin'
Why
use hooks
● Tweak
functionality/output
to better fit your
needs
● Maintain your
customizations when
updating
@NowellVanHoesen5 W's of Hookin'
Why
use hooks
● Tweak
functionality/output
to better fit your
needs
● Maintain your
customizations when
updating
create hooks
@NowellVanHoesen5 W's of Hookin'
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'
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'
Where...
can I find them
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
● Plugins
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
● Plugins
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
● Plugins
● WordPress core
@NowellVanHoesen5 W's of Hookin'
Where...
can I find them
● WordPress core
● Themes
● Plugins
can I create them
● Themes
● Plugins
● WordPress core
@NowellVanHoesen5 W's of Hookin'
How?
Actions Filters
@NowellVanHoesen5 W's of Hookin'
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
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
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
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
Action hook example 1
// wp_enqueue_scripts action
add_action( 'wp_enqueue_scripts', 'nv_added_styles' );
function nv_added_styles() {
if ( !is_admin() ) {
wp_register_style(
'nv-ie-fix',
get_bloginfo( 'stylesheet_directory' ) . '/ie.css',
false
);
$GLOBALS['wp_styles']->add_data(
'nv-ie-fix',
'conditional',
'lte IE 8'
);
wp_enqueue_style( 'nv-ie-fix' );
}
}
@NowellVanHoesen5 W's of Hookin'
Action hook example 2
add_action( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
global $wp_the_query;
if( $wp_the_query === $query && $query->is_home() ) {
add_filter( 'posts_where' , 'posts_where' );
$category_id = get_cat_ID( 'Scribblings' );
$query->set( 'cat', $category_id );
} else if ( is_archive() && is_date() && !is_category()) {
if ( !isset( $query->query_vars['post_type'] ) ) {
$query->set( 'post_type', array( 'post', 'myoldhouse', 'snapshots' ) );
$query->set( 'posts_per_page', -1 );
}
}
}
function posts_where( $where ) {
$where = " AND ( ( wp_term_relationships.term_taxonomy_id IN (1) AND wp_posts.post_type =
'post' ) OR ( wp_posts.post_type IN ('myoldhouse', 'snapshots') ) ) AND (wp_posts.post_status =
'publish' OR wp_posts.post_status = 'private')";
return $where;
}
@NowellVanHoesen5 W's of Hookin'
Filter hook examples
add_filter( 'the_title', 'nv_the_title', 10, 2 );
function nv_the_title( $title, $id ) {
if ( !is_admin() ) {
$title = 'WCCbus - ' . $title;
}
return $title;
}
// what core runs
return apply_filters( 'the_title', $title, $id );
add_filter( 'enter_title_here', 'change_default_post_title', 10, 2 );
function change_default_post_title( $text, $post ) {
if ( 'post' == get_post_type( $post ) ) {
return $text . “ - Required”;
}
}
@NowellVanHoesen5 W's of Hookin'
Time to go live...
@NowellVanHoesen5 W's of Hookin'
Time to go live...
@NowellVanHoesen5 W's of Hookin'
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/

Contenu connexe

Tendances

RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The FutureTracy Lee
 
Dev with github enterprise
Dev with github enterpriseDev with github enterprise
Dev with github enterpriseHiroshi Wada
 
Michael King - The Thin Line Between Seth Godin & Neil Strauss
Michael King - The Thin Line Between Seth Godin & Neil StraussMichael King - The Thin Line Between Seth Godin & Neil Strauss
Michael King - The Thin Line Between Seth Godin & Neil StraussWebrazzi
 
Functions.php - It's Not Just For Developers
Functions.php - It's Not Just For DevelopersFunctions.php - It's Not Just For Developers
Functions.php - It's Not Just For DevelopersEric Mann
 
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesUsing Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesTracy Lee
 
Building Rackspace Cloud Monitoring
Building Rackspace Cloud MonitoringBuilding Rackspace Cloud Monitoring
Building Rackspace Cloud Monitoringgdusbabek
 
Interns What Is DevOps
Interns What Is DevOpsInterns What Is DevOps
Interns What Is DevOpsAaron Blythe
 
Telco Cloud How operators are using the Cloud to unlock the core network and ...
Telco Cloud How operators are using the Cloud to unlock the core network and ...Telco Cloud How operators are using the Cloud to unlock the core network and ...
Telco Cloud How operators are using the Cloud to unlock the core network and ...Alan Quayle
 
ESADE - Plugged-In Management
ESADE - Plugged-In ManagementESADE - Plugged-In Management
ESADE - Plugged-In ManagementTerri Griffith
 
DevOps 101 for data professionals
DevOps 101 for data professionalsDevOps 101 for data professionals
DevOps 101 for data professionalsAlex Yates
 
Content sourcing with Red Bull
Content sourcing with Red BullContent sourcing with Red Bull
Content sourcing with Red BullMichael Kurz
 
Contributing to Impala
Contributing to ImpalaContributing to Impala
Contributing to ImpalaCloudera, Inc.
 
Why you should add React to your Rails application now!
Why you should add React to your Rails application now!Why you should add React to your Rails application now!
Why you should add React to your Rails application now!David Roberts
 
Open Source Principles for Internal Engineering Teams
Open Source Principles for Internal Engineering TeamsOpen Source Principles for Internal Engineering Teams
Open Source Principles for Internal Engineering TeamsAll Things Open
 

Tendances (16)

Drupal DOMinate
Drupal DOMinateDrupal DOMinate
Drupal DOMinate
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
 
Dev with github enterprise
Dev with github enterpriseDev with github enterprise
Dev with github enterprise
 
Michael King - The Thin Line Between Seth Godin & Neil Strauss
Michael King - The Thin Line Between Seth Godin & Neil StraussMichael King - The Thin Line Between Seth Godin & Neil Strauss
Michael King - The Thin Line Between Seth Godin & Neil Strauss
 
Functions.php - It's Not Just For Developers
Functions.php - It's Not Just For DevelopersFunctions.php - It's Not Just For Developers
Functions.php - It's Not Just For Developers
 
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesUsing Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
 
Building Rackspace Cloud Monitoring
Building Rackspace Cloud MonitoringBuilding Rackspace Cloud Monitoring
Building Rackspace Cloud Monitoring
 
Interns What Is DevOps
Interns What Is DevOpsInterns What Is DevOps
Interns What Is DevOps
 
Telco Cloud How operators are using the Cloud to unlock the core network and ...
Telco Cloud How operators are using the Cloud to unlock the core network and ...Telco Cloud How operators are using the Cloud to unlock the core network and ...
Telco Cloud How operators are using the Cloud to unlock the core network and ...
 
Refactoring a web application with Python
Refactoring a web application with PythonRefactoring a web application with Python
Refactoring a web application with Python
 
ESADE - Plugged-In Management
ESADE - Plugged-In ManagementESADE - Plugged-In Management
ESADE - Plugged-In Management
 
DevOps 101 for data professionals
DevOps 101 for data professionalsDevOps 101 for data professionals
DevOps 101 for data professionals
 
Content sourcing with Red Bull
Content sourcing with Red BullContent sourcing with Red Bull
Content sourcing with Red Bull
 
Contributing to Impala
Contributing to ImpalaContributing to Impala
Contributing to Impala
 
Why you should add React to your Rails application now!
Why you should add React to your Rails application now!Why you should add React to your Rails application now!
Why you should add React to your Rails application now!
 
Open Source Principles for Internal Engineering Teams
Open Source Principles for Internal Engineering TeamsOpen Source Principles for Internal Engineering Teams
Open Source Principles for Internal Engineering Teams
 

Similaire à 5 W's of Hookin'

Hooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp ColumbusHooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp ColumbusShawn Hooper
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Ian Wilson
 
WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)MuhammadKashif596
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...WordCamp Sydney
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Alessandro Nadalin
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Adam Tomat
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPresstopher1kenobe
 
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02sos informatique
 
An easy guide to Plugin Development
An easy guide to Plugin DevelopmentAn easy guide to Plugin Development
An easy guide to Plugin DevelopmentShinichi Nishikawa
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
php[world] Hooks, Actions and Filters Oh My!
php[world] Hooks, Actions and Filters Oh My!php[world] Hooks, Actions and Filters Oh My!
php[world] Hooks, Actions and Filters Oh My!David Wolfpaw
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexRyan Weaver
 
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)Rodolfo Melogli
 
Theming Wordpress with Adobe
Theming Wordpress with AdobeTheming Wordpress with Adobe
Theming Wordpress with AdobeGrace Solivan
 
Developing client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp EdmontonDeveloping client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp EdmontonCurtis McHale
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designerselliotjaystocks
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 

Similaire à 5 W's of Hookin' (20)

Hooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp ColumbusHooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp Columbus
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)
 
Cain & Obenland — Episode 4
Cain & Obenland — Episode 4Cain & Obenland — Episode 4
Cain & Obenland — Episode 4
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
Hey, I just met AngularJS, and this is crazy, so here’s my JavaScript, let’s ...
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
 
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
 
An easy guide to Plugin Development
An easy guide to Plugin DevelopmentAn easy guide to Plugin Development
An easy guide to Plugin Development
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
php[world] Hooks, Actions and Filters Oh My!
php[world] Hooks, Actions and Filters Oh My!php[world] Hooks, Actions and Filters Oh My!
php[world] Hooks, Actions and Filters Oh My!
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
Theming Wordpress with Adobe
Theming Wordpress with AdobeTheming Wordpress with Adobe
Theming Wordpress with Adobe
 
Developing client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp EdmontonDeveloping client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp Edmonton
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designers
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 

Dernier

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

5 W's of Hookin'

  • 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'
  • 11. Why use hooks ● Tweak functionality/output to better fit your needs @NowellVanHoesen5 W's of Hookin'
  • 12. Why use hooks ● Tweak functionality/output to better fit your needs ● Maintain your customizations when updating @NowellVanHoesen5 W's of Hookin'
  • 13. Why use hooks ● Tweak functionality/output to better fit your needs ● Maintain your customizations when updating create hooks @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'
  • 16. Where... can I find them @NowellVanHoesen5 W's of Hookin'
  • 17. Where... can I find them ● WordPress core @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
  • 30. Action hook example 1 // wp_enqueue_scripts action add_action( 'wp_enqueue_scripts', 'nv_added_styles' ); function nv_added_styles() { if ( !is_admin() ) { wp_register_style( 'nv-ie-fix', get_bloginfo( 'stylesheet_directory' ) . '/ie.css', false ); $GLOBALS['wp_styles']->add_data( 'nv-ie-fix', 'conditional', 'lte IE 8' ); wp_enqueue_style( 'nv-ie-fix' ); } } @NowellVanHoesen5 W's of Hookin'
  • 31. Action hook example 2 add_action( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { global $wp_the_query; if( $wp_the_query === $query && $query->is_home() ) { add_filter( 'posts_where' , 'posts_where' ); $category_id = get_cat_ID( 'Scribblings' ); $query->set( 'cat', $category_id ); } else if ( is_archive() && is_date() && !is_category()) { if ( !isset( $query->query_vars['post_type'] ) ) { $query->set( 'post_type', array( 'post', 'myoldhouse', 'snapshots' ) ); $query->set( 'posts_per_page', -1 ); } } } function posts_where( $where ) { $where = " AND ( ( wp_term_relationships.term_taxonomy_id IN (1) AND wp_posts.post_type = 'post' ) OR ( wp_posts.post_type IN ('myoldhouse', 'snapshots') ) ) AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')"; return $where; } @NowellVanHoesen5 W's of Hookin'
  • 32. Filter hook examples add_filter( 'the_title', 'nv_the_title', 10, 2 ); function nv_the_title( $title, $id ) { if ( !is_admin() ) { $title = 'WCCbus - ' . $title; } return $title; } // what core runs return apply_filters( 'the_title', $title, $id ); add_filter( 'enter_title_here', 'change_default_post_title', 10, 2 ); function change_default_post_title( $text, $post ) { if ( 'post' == get_post_type( $post ) ) { return $text . “ - Required”; } } @NowellVanHoesen5 W's of Hookin'
  • 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/