SlideShare a Scribd company logo
WordPress Filters and
                         Actions @glennansley
WordCamp Raleigh
           2011
Whatʼs the big deal?
WordCamp Raleigh
           2011
Whatʼs the big deal?
WordCamp Raleigh   • Customization of core functionality
           2011
Whatʼs the big deal?
WordCamp Raleigh   • Customization of core functionality
           2011
                   • Separation between 3rd party code and
                    the core codebase
Whatʼs the big deal?
WordCamp Raleigh   • Customization of core functionality
           2011
                   • Separation between 3rd party code and
                       the core codebase
                   •   Content Management Systems
                   •   Customer Relationship Management systems
                   •   PHP frameworks
                   •   Robust social networks
                   •   Micro blogging sites
                   •   E-commerce shops
                   •   Online gaming frameworks
                   •   Software as a Service frameworks
                   •   Multimedia galleries
Whatʼs the big deal?
WordCamp Raleigh   • Customization of core functionality
           2011
                   • Separation between 3rd party code and
                       the core codebase
                   •   Content Management Systems
                   •   Customer Relationship Management systems
                   •   PHP frameworks
                   •   Robust social networks
                   •   Micro blogging sites
                   •   E-commerce shops
                   •   Online gaming frameworks
                   •   Software as a Service frameworks
                   •   Multimedia galleries




                   22 million estimated installs of WordPress
Itʼs all about the timing
WordCamp Raleigh
           2011
Important Components
WordCamp Raleigh
           2011
                   Hooks
                   Special WordPress functions created to give other
                   code access to the PHP script or to the data at
                   specific points during its execution.
Important Components
WordCamp Raleigh
           2011
                   Hooks
                   Special WordPress functions created to give other
                   code access to the PHP script or to the data at
                   specific points during its execution.
                   examples:
                   • apply_filters
                   • do_action
                   • apply_filters_ref_array
                   • do_action_ref_array
Important Components
WordCamp Raleigh
           2011
                   Actions
                   Special WordPress functions that are created for
                   the purpose of altering the original course of the
                   PHP script.
Important Components
WordCamp Raleigh
           2011
                   Actions
                   Special WordPress functions that are created for
                   the purpose of altering the original course of the
                   PHP script.
                   examples:
                   •   wp_update_plugins

                   •   wp_old_slug_redirect

                   •   _publish_post_hook

                   •   smilies_init
Important Components
WordCamp Raleigh
           2011
                   Filters
                   Special WordPress functions that are created for
                   the purpose of parsing or altering the data
                   handled by the PHP script.
Important Components
WordCamp Raleigh
           2011
                   Filters
                   Special WordPress functions that are created for
                   the purpose of parsing or altering the data
                   handled by the PHP script.
                   examples:
                   •   sanitize_email

                   •   capital_P_dangit

                   •   wpautop

                   •   strip_tags
Important Components
WordCamp Raleigh
           2011
                   Tags
                   Tags are unique strings used by WordPress to
                   associate specific instances of a hook with
                   specific action or filter functions
Important Components
WordCamp Raleigh
           2011
                   Tags
                   Tags are unique strings used by WordPress to
                   associate specific instances of a hook with
                   specific action or filter functions
                   examples:
                   •   init

                   •   template_redirect

                   •   the_content

                   •   wp_footer
Important Components
WordCamp Raleigh
           2011
                   $wp_filter
                   A special WordPress variable that contains all
                   hook tags used added on the current page load
                   along with any associated filter or action functions.
Important Components
WordCamp Raleigh
           2011
                   Utility Functions
                   Special WordPress functions developed to help
                   manage and maintain the association between
                   hooks and filter for action functions.
Important Components
WordCamp Raleigh
           2011
                   Utility Functions
                   Special WordPress functions developed to help
                   manage and maintain the association between
                   hooks and filter for action functions.
                   examples:
                   •   add_action            •   add_filter

                   •   remove_action         •   remove_filter

                   •   remove_all_actions    •   remove_all_filters

                   •   has_action            •   has_filter

                                             •   current_filter
Quick Review
                   • WordPress is a PHP script.
WordCamp Raleigh   • Hooks that provide access to other code blocks are
           2011     placed throughout the script.

                   • Tags are used in association with these hooks to identify
                    the location of each instance within the script.

                   • Filters and actions are special functions able to modify
                    the data or the course of the script without altering the
                    core code.

                   • $wp_filter is an associative array that stores tags along
                    with their associated filter or action functions.

                   • Utility functions exist to help manage and maintain
                    those relationships.
Examples
WordCamp Raleigh
           2011
                   Add a basic filter
                   This filter is very simple. It only uses the
                   mandatory parameters and it references a
                   WordPress function.

                   add_filter( ‘the_title’, ‘wptexturize’);

                   parent_name = apply_filters( 'the_title', $parent->post_title,
                     $parent->ID );
Examples
WordCamp Raleigh
           2011
                   Add a basic filter with priority
                   This filter uses a 3rd and optional parameter for
                   priority. If the 3rd parameter isn’t set, it defaults to
                   10. The lower the number, the higher the priority.


                   add_filter( ‘comment_text’, ‘make_clickable’, 9 );

                   $comment = apply_filters( 'comment_text', $comment );
Examples
WordCamp Raleigh
           2011    Add an action with the accepted
                   args parameter
                   This filter uses a 4th and optional parameter for
                   accepted params. If not passed, it defaults to 1.
                   add_action(
                      ‘post_updated’,
                      ‘wp_check_for_changed_slugs’,
                      12,
                      3
                   );

                   do_action( 'post_updated', $post_ID,
                     $post_after, $post_before);
Examples
WordCamp Raleigh
           2011    Attaching a filter to the
                   apply_filters_ref_array
                   This hook only passes your filter function one
                   parameter but it’s much more powerful for a
                   couple of reasons.
                   $this->posts = apply_filters_ref_array(
                    'posts_results',
                    array( $this->posts, &$this )
                   );

                   add_filter( 'posts_results', 'testers' );
                   function testers ( $query ) {
                       echo "<pre>";print_r( $query );die();
                   }
Examples
                       Attaching a filter to the
WordCamp Raleigh
           2011        apply_filters_ref_array
                   Array
                   (
                       [0] => stdClass Object
                           (
                               [ID] => 3456
                               [post_author] => 2
                               [post_date] => 2010-12-29 15:20:57
                               [post_date_gmt] => 2010-12-29 19:20:57
                               [post_content] => [simplemap taxonomy_field_type='checkboxes']
                               [post_title] => SimpleMap
                               [post_excerpt] =>
                               [post_status] => publish
                               [comment_status] => open
                               [ping_status] => open
                               [post_password] =>
                               [post_name] => simplemap
                               [to_ping] =>
                               [pinged] =>
                               [post_modified] => 2011-05-08 23:13:14
                               [post_modified_gmt] => 2011-05-09 03:13:14
                               [post_content_filtered] =>
                               [post_parent] => 0
                               [guid] => http://localhost/wptrunk/?page_id=3456
                               [menu_order] => 0
                               [post_type] => page
                               [post_mime_type] =>
                               [comment_count] => 0
                           )

                   )
Examples
WordCamp Raleigh   Attaching an action to the
           2011
                   do_action_ref_array
                   This hook only passes your action function one
                   parameter but it’s much more powerful for the
                   same reasons as apply_filters_ref_array.
                   do_action_ref_array(
                      'pre_get_posts',
                      array(&$this)
                   );

                   add_action( 'pre_get_posts', 'testers' );
                   function testers ( $query ) {
                       echo "<pre>";print_r( $query );
                       die();
                   }
Examples
                    Attaching an action to the
WordCamp Raleigh
           2011     do_action_ref_array
                   WP_Query Object
                   (
                       [query_vars] => Array
                           (
                               [error] =>
                               [m] => 0
                               [p] => 0
                               [post_parent] =>
                               [subpost] =>
                               [subpost_id] =>
                               [attachment] =>
                               [attachment_id] => 0
                               [name] =>
                               [static] =>
                               [pagename] =>
                               [page_id] => 3456
                               [second] =>
                               [minute] =>
                               [hour] =>
                               [day] => 0
                               [monthnum] => 0
                               [year] => 0
                               [w] => 0
                               [category_name] =>
                               [tag] =>
                               [cat] =>
                               [tag_id] =>
                               [author_name] =>
Common Mistakes
                   Deprecated tags
WordCamp Raleigh
           2011    http://adambrown.info/p/wp_hooks/hook?old=1

                   Bad timing
                   If your plugin calls add_action( ‘wp_head’, ‘...’ ) after the
                   do_action( ‘wp_head’ ); hooks has been called, your
                   action won’t ever be fired. Additionally, you can’t use

                   add_action or add_filter functions before they’ve been
                   defined by WordPress.

                   Echoing data in filters
                   This really will cause the world to end

                   Bad or No data returned by filter
                   This is a handshake. Give back what you receive.
Common Mistakes
                   Mismatched parameters in remove_*
WordCamp Raleigh
           2011    If you’re using remove_action or remove_filter, make
                   sure that you’re using the same params used with

                   add_action and add_filter

                   Missing parameters
                   Make sure you’ve used the 4th accepted_args param

                   with add_action or add_filter.
Frequently Asked
                            Questions
                   Can I use the hook API outside of WordPress
WordCamp Raleigh
           2011    Yes. wp-includes/plugin.php & http://backpress.org/

                   Are there other ʻhooksʻ in the code?

                   Yes. http://codex.wordpress.org/WordPress_API's

                   What if I canʼt find a needed hook
                   Look harder. Check further up the code.
                   http://wordpress.org/news/2009/05/ideas/

                   Can I remove remove WordPress core hooks?
                   Yes. /wp-includes/default-filters.php

                   Can I add my own hook tags?
                   Yes. I would encourage it.
Additional Resources
WordCamp Raleigh
                   Online
           2011
                   •   http://codex.wordpress.org/Plugin_AP
                       http://codex.wordpress.org/Plugin_API/Filter_Reference
                   •   http://codex.wordpress.org/Plugin_API/Action_Reference
                   •   http://codex.wordpress.org/Plugin_API/Hooks_2.0.x
                   •   http://wpcandy.com/teaches/how-to-use-wordpress-hooks
                   •   http://www.nathanrice.net/blog/an-introduction-to-wordpress-action-
                       hooks/
                   •   http://adambrown.info/p/wp_hooks
                   •   http://wpengineer.com/1302/define-your-own-wordpress-hooks/
                   •   http://wordpress.org/extend/plugins/wordpress-hook-sniffer/
                   •   http://wp-roadmap.com/demo/
                   •   http://andy.wordpress.com/2008/10/30/wordpress-include-stack/


                   Offline
                   •   Professional WordPress Plugin Development
                   •   Professional WordPress
                   •   The WordPress Bible
WordPress Filters and
                         Actions @glennansley
WordCamp Raleigh
           2011

More Related Content

What's hot

Pitfalls of Migrating to SharePoint 2010
Pitfalls of Migrating to SharePoint 2010Pitfalls of Migrating to SharePoint 2010
Pitfalls of Migrating to SharePoint 2010Dan Usher
 
20100604 unyoug apex40_bauser
20100604 unyoug apex40_bauser20100604 unyoug apex40_bauser
20100604 unyoug apex40_bauserahmed farouk
 
FatWire Tutorial For Site Studio Developers
FatWire Tutorial For Site Studio DevelopersFatWire Tutorial For Site Studio Developers
FatWire Tutorial For Site Studio DevelopersBrian Huff
 
Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...
Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...
Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...Brian Huff
 
Web Apps atop a Content Repository
Web Apps atop a Content RepositoryWeb Apps atop a Content Repository
Web Apps atop a Content RepositoryGabriel Walt
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update referencesandeepji_choudhary
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden
 
Integrating ADF Mobile with WebCenter
Integrating ADF Mobile with WebCenterIntegrating ADF Mobile with WebCenter
Integrating ADF Mobile with WebCenterBrian Huff
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesMert Çalışkan
 
Reaching 1 Million APIs and what to do when we get there
Reaching 1 Million APIs and what to do when we get thereReaching 1 Million APIs and what to do when we get there
Reaching 1 Million APIs and what to do when we get there3scale
 
Deep Dive: Oracle WebCenter Content Tips and Traps!
Deep Dive: Oracle WebCenter Content Tips and Traps!Deep Dive: Oracle WebCenter Content Tips and Traps!
Deep Dive: Oracle WebCenter Content Tips and Traps!Brian Huff
 
WebCenter Content 11g Upgrade Webinar - March 2013
WebCenter Content 11g Upgrade Webinar - March 2013WebCenter Content 11g Upgrade Webinar - March 2013
WebCenter Content 11g Upgrade Webinar - March 2013Fishbowl Solutions
 
Best Practices and Tips on Migrating a Legacy-Based CMS to Drupal
Best Practices and Tips on Migrating a Legacy-Based CMS to DrupalBest Practices and Tips on Migrating a Legacy-Based CMS to Drupal
Best Practices and Tips on Migrating a Legacy-Based CMS to DrupalMediacurrent
 
Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...
Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...
Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...Brian Huff
 
Three WEM Dev Tricks
Three WEM Dev TricksThree WEM Dev Tricks
Three WEM Dev TricksGabriel Walt
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6Bert Ertman
 
Lessons learned from building Eclipse-based add-ons for commercial modeling t...
Lessons learned from building Eclipse-based add-ons for commercial modeling t...Lessons learned from building Eclipse-based add-ons for commercial modeling t...
Lessons learned from building Eclipse-based add-ons for commercial modeling t...IncQuery Labs
 
Introduction to PowerShell - Be a PowerShell Hero - SPFest workshop
Introduction to PowerShell - Be a PowerShell Hero - SPFest workshopIntroduction to PowerShell - Be a PowerShell Hero - SPFest workshop
Introduction to PowerShell - Be a PowerShell Hero - SPFest workshopMichael Blumenthal (Microsoft MVP)
 
A Succesful WebCenter Upgrade: What You Need to Know
A Succesful WebCenter Upgrade: What You Need to KnowA Succesful WebCenter Upgrade: What You Need to Know
A Succesful WebCenter Upgrade: What You Need to KnowFishbowl Solutions
 

What's hot (20)

Pitfalls of Migrating to SharePoint 2010
Pitfalls of Migrating to SharePoint 2010Pitfalls of Migrating to SharePoint 2010
Pitfalls of Migrating to SharePoint 2010
 
20100604 unyoug apex40_bauser
20100604 unyoug apex40_bauser20100604 unyoug apex40_bauser
20100604 unyoug apex40_bauser
 
FatWire Tutorial For Site Studio Developers
FatWire Tutorial For Site Studio DevelopersFatWire Tutorial For Site Studio Developers
FatWire Tutorial For Site Studio Developers
 
Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...
Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...
Seamless Integrations between WebCenter Content, Site Studio, and WebCenter S...
 
Web Apps atop a Content Repository
Web Apps atop a Content RepositoryWeb Apps atop a Content Repository
Web Apps atop a Content Repository
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
 
Integrating ADF Mobile with WebCenter
Integrating ADF Mobile with WebCenterIntegrating ADF Mobile with WebCenter
Integrating ADF Mobile with WebCenter
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
 
Reaching 1 Million APIs and what to do when we get there
Reaching 1 Million APIs and what to do when we get thereReaching 1 Million APIs and what to do when we get there
Reaching 1 Million APIs and what to do when we get there
 
Deep Dive: Oracle WebCenter Content Tips and Traps!
Deep Dive: Oracle WebCenter Content Tips and Traps!Deep Dive: Oracle WebCenter Content Tips and Traps!
Deep Dive: Oracle WebCenter Content Tips and Traps!
 
WebCenter Content 11g Upgrade Webinar - March 2013
WebCenter Content 11g Upgrade Webinar - March 2013WebCenter Content 11g Upgrade Webinar - March 2013
WebCenter Content 11g Upgrade Webinar - March 2013
 
Best Practices and Tips on Migrating a Legacy-Based CMS to Drupal
Best Practices and Tips on Migrating a Legacy-Based CMS to DrupalBest Practices and Tips on Migrating a Legacy-Based CMS to Drupal
Best Practices and Tips on Migrating a Legacy-Based CMS to Drupal
 
Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...
Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...
Integrating ECM (WebCenter Content) with your Enterprise! 5 Tips to Try, 5 Tr...
 
Three WEM Dev Tricks
Three WEM Dev TricksThree WEM Dev Tricks
Three WEM Dev Tricks
 
JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6JavaOne 2011: Migrating Spring Applications to Java EE 6
JavaOne 2011: Migrating Spring Applications to Java EE 6
 
Lessons learned from building Eclipse-based add-ons for commercial modeling t...
Lessons learned from building Eclipse-based add-ons for commercial modeling t...Lessons learned from building Eclipse-based add-ons for commercial modeling t...
Lessons learned from building Eclipse-based add-ons for commercial modeling t...
 
Introduction to PowerShell - Be a PowerShell Hero - SPFest workshop
Introduction to PowerShell - Be a PowerShell Hero - SPFest workshopIntroduction to PowerShell - Be a PowerShell Hero - SPFest workshop
Introduction to PowerShell - Be a PowerShell Hero - SPFest workshop
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
A Succesful WebCenter Upgrade: What You Need to Know
A Succesful WebCenter Upgrade: What You Need to KnowA Succesful WebCenter Upgrade: What You Need to Know
A Succesful WebCenter Upgrade: What You Need to Know
 

Similar to WordPress Filters and Actions

Best Laravel Development Company In the USA
Best Laravel Development Company In the USABest Laravel Development Company In the USA
Best Laravel Development Company In the USAtechnoprofiles
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Shahrzad Peyman
 
Refactoring Fat Models: Trying to be a Software Engineer
Refactoring Fat Models: Trying to be a Software EngineerRefactoring Fat Models: Trying to be a Software Engineer
Refactoring Fat Models: Trying to be a Software EngineerJyaasa Technologies
 
Why Choose Laravel Framework for Your Next Web Development Project?
Why Choose Laravel Framework for Your Next Web Development Project?Why Choose Laravel Framework for Your Next Web Development Project?
Why Choose Laravel Framework for Your Next Web Development Project?Windzoon Technologies
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slidesKeep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slidesJer Clarke
 
Laravel - A Trending PHP Framework
Laravel - A Trending PHP FrameworkLaravel - A Trending PHP Framework
Laravel - A Trending PHP Frameworkijtsrd
 
GCE11 Apache Rave Presentation
GCE11 Apache Rave PresentationGCE11 Apache Rave Presentation
GCE11 Apache Rave Presentationmarpierc
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your BusinessFabernovel
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Mack Hardy
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patternsCorey Oordt
 
Advanced features of Laravel development
Advanced features of Laravel developmentAdvanced features of Laravel development
Advanced features of Laravel developmentAResourcePool
 
Prominent Back-end frameworks to consider in 2022!
Prominent Back-end frameworks to consider in 2022!Prominent Back-end frameworks to consider in 2022!
Prominent Back-end frameworks to consider in 2022!Shelly Megan
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--devaltsav
 
Popular PHP laravel frameworks in app development
Popular PHP laravel frameworks in app developmentPopular PHP laravel frameworks in app development
Popular PHP laravel frameworks in app developmentdeorwine infotech
 

Similar to WordPress Filters and Actions (20)

Miami2015
Miami2015Miami2015
Miami2015
 
Introduction to Wordmap
Introduction to WordmapIntroduction to Wordmap
Introduction to Wordmap
 
Best Laravel Development Company In the USA
Best Laravel Development Company In the USABest Laravel Development Company In the USA
Best Laravel Development Company In the USA
 
Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2Object Oriented Programming with Laravel - Session 2
Object Oriented Programming with Laravel - Session 2
 
Refactoring Fat Models: Trying to be a Software Engineer
Refactoring Fat Models: Trying to be a Software EngineerRefactoring Fat Models: Trying to be a Software Engineer
Refactoring Fat Models: Trying to be a Software Engineer
 
Top 5 advanced php framework in 2018
Top 5 advanced php framework in 2018Top 5 advanced php framework in 2018
Top 5 advanced php framework in 2018
 
Why Choose Laravel Framework for Your Next Web Development Project?
Why Choose Laravel Framework for Your Next Web Development Project?Why Choose Laravel Framework for Your Next Web Development Project?
Why Choose Laravel Framework for Your Next Web Development Project?
 
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slidesKeep Your Code Organized! WordCamp Montreal 2013 Presentation slides
Keep Your Code Organized! WordCamp Montreal 2013 Presentation slides
 
Laravel - A Trending PHP Framework
Laravel - A Trending PHP FrameworkLaravel - A Trending PHP Framework
Laravel - A Trending PHP Framework
 
GCE11 Apache Rave Presentation
GCE11 Apache Rave PresentationGCE11 Apache Rave Presentation
GCE11 Apache Rave Presentation
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business
 
React vs laravel
React vs laravelReact vs laravel
React vs laravel
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
Pluggable patterns
Pluggable patternsPluggable patterns
Pluggable patterns
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
Advanced features of Laravel development
Advanced features of Laravel developmentAdvanced features of Laravel development
Advanced features of Laravel development
 
Prominent Back-end frameworks to consider in 2022!
Prominent Back-end frameworks to consider in 2022!Prominent Back-end frameworks to consider in 2022!
Prominent Back-end frameworks to consider in 2022!
 
Presentation 1 Web--dev
Presentation 1 Web--devPresentation 1 Web--dev
Presentation 1 Web--dev
 
Popular PHP laravel frameworks in app development
Popular PHP laravel frameworks in app developmentPopular PHP laravel frameworks in app development
Popular PHP laravel frameworks in app development
 
Laravel Presentation
Laravel PresentationLaravel Presentation
Laravel Presentation
 

Recently uploaded

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Alison B. Lowndes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...Elena Simperl
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 

Recently uploaded (20)

Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 

WordPress Filters and Actions

  • 1. WordPress Filters and Actions @glennansley WordCamp Raleigh 2011
  • 2. Whatʼs the big deal? WordCamp Raleigh 2011
  • 3. Whatʼs the big deal? WordCamp Raleigh • Customization of core functionality 2011
  • 4. Whatʼs the big deal? WordCamp Raleigh • Customization of core functionality 2011 • Separation between 3rd party code and the core codebase
  • 5. Whatʼs the big deal? WordCamp Raleigh • Customization of core functionality 2011 • Separation between 3rd party code and the core codebase • Content Management Systems • Customer Relationship Management systems • PHP frameworks • Robust social networks • Micro blogging sites • E-commerce shops • Online gaming frameworks • Software as a Service frameworks • Multimedia galleries
  • 6. Whatʼs the big deal? WordCamp Raleigh • Customization of core functionality 2011 • Separation between 3rd party code and the core codebase • Content Management Systems • Customer Relationship Management systems • PHP frameworks • Robust social networks • Micro blogging sites • E-commerce shops • Online gaming frameworks • Software as a Service frameworks • Multimedia galleries 22 million estimated installs of WordPress
  • 7. Itʼs all about the timing WordCamp Raleigh 2011
  • 8. Important Components WordCamp Raleigh 2011 Hooks Special WordPress functions created to give other code access to the PHP script or to the data at specific points during its execution.
  • 9. Important Components WordCamp Raleigh 2011 Hooks Special WordPress functions created to give other code access to the PHP script or to the data at specific points during its execution. examples: • apply_filters • do_action • apply_filters_ref_array • do_action_ref_array
  • 10. Important Components WordCamp Raleigh 2011 Actions Special WordPress functions that are created for the purpose of altering the original course of the PHP script.
  • 11. Important Components WordCamp Raleigh 2011 Actions Special WordPress functions that are created for the purpose of altering the original course of the PHP script. examples: • wp_update_plugins • wp_old_slug_redirect • _publish_post_hook • smilies_init
  • 12. Important Components WordCamp Raleigh 2011 Filters Special WordPress functions that are created for the purpose of parsing or altering the data handled by the PHP script.
  • 13. Important Components WordCamp Raleigh 2011 Filters Special WordPress functions that are created for the purpose of parsing or altering the data handled by the PHP script. examples: • sanitize_email • capital_P_dangit • wpautop • strip_tags
  • 14. Important Components WordCamp Raleigh 2011 Tags Tags are unique strings used by WordPress to associate specific instances of a hook with specific action or filter functions
  • 15. Important Components WordCamp Raleigh 2011 Tags Tags are unique strings used by WordPress to associate specific instances of a hook with specific action or filter functions examples: • init • template_redirect • the_content • wp_footer
  • 16. Important Components WordCamp Raleigh 2011 $wp_filter A special WordPress variable that contains all hook tags used added on the current page load along with any associated filter or action functions.
  • 17. Important Components WordCamp Raleigh 2011 Utility Functions Special WordPress functions developed to help manage and maintain the association between hooks and filter for action functions.
  • 18. Important Components WordCamp Raleigh 2011 Utility Functions Special WordPress functions developed to help manage and maintain the association between hooks and filter for action functions. examples: • add_action • add_filter • remove_action • remove_filter • remove_all_actions • remove_all_filters • has_action • has_filter • current_filter
  • 19. Quick Review • WordPress is a PHP script. WordCamp Raleigh • Hooks that provide access to other code blocks are 2011 placed throughout the script. • Tags are used in association with these hooks to identify the location of each instance within the script. • Filters and actions are special functions able to modify the data or the course of the script without altering the core code. • $wp_filter is an associative array that stores tags along with their associated filter or action functions. • Utility functions exist to help manage and maintain those relationships.
  • 20. Examples WordCamp Raleigh 2011 Add a basic filter This filter is very simple. It only uses the mandatory parameters and it references a WordPress function. add_filter( ‘the_title’, ‘wptexturize’); parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
  • 21. Examples WordCamp Raleigh 2011 Add a basic filter with priority This filter uses a 3rd and optional parameter for priority. If the 3rd parameter isn’t set, it defaults to 10. The lower the number, the higher the priority. add_filter( ‘comment_text’, ‘make_clickable’, 9 ); $comment = apply_filters( 'comment_text', $comment );
  • 22. Examples WordCamp Raleigh 2011 Add an action with the accepted args parameter This filter uses a 4th and optional parameter for accepted params. If not passed, it defaults to 1. add_action( ‘post_updated’, ‘wp_check_for_changed_slugs’, 12, 3 ); do_action( 'post_updated', $post_ID, $post_after, $post_before);
  • 23. Examples WordCamp Raleigh 2011 Attaching a filter to the apply_filters_ref_array This hook only passes your filter function one parameter but it’s much more powerful for a couple of reasons. $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); add_filter( 'posts_results', 'testers' ); function testers ( $query ) { echo "<pre>";print_r( $query );die(); }
  • 24. Examples Attaching a filter to the WordCamp Raleigh 2011 apply_filters_ref_array Array ( [0] => stdClass Object ( [ID] => 3456 [post_author] => 2 [post_date] => 2010-12-29 15:20:57 [post_date_gmt] => 2010-12-29 19:20:57 [post_content] => [simplemap taxonomy_field_type='checkboxes'] [post_title] => SimpleMap [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => simplemap [to_ping] => [pinged] => [post_modified] => 2011-05-08 23:13:14 [post_modified_gmt] => 2011-05-09 03:13:14 [post_content_filtered] => [post_parent] => 0 [guid] => http://localhost/wptrunk/?page_id=3456 [menu_order] => 0 [post_type] => page [post_mime_type] => [comment_count] => 0 ) )
  • 25. Examples WordCamp Raleigh Attaching an action to the 2011 do_action_ref_array This hook only passes your action function one parameter but it’s much more powerful for the same reasons as apply_filters_ref_array. do_action_ref_array( 'pre_get_posts', array(&$this) ); add_action( 'pre_get_posts', 'testers' ); function testers ( $query ) { echo "<pre>";print_r( $query ); die(); }
  • 26. Examples Attaching an action to the WordCamp Raleigh 2011 do_action_ref_array WP_Query Object ( [query_vars] => Array ( [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 3456 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] =>
  • 27. Common Mistakes Deprecated tags WordCamp Raleigh 2011 http://adambrown.info/p/wp_hooks/hook?old=1 Bad timing If your plugin calls add_action( ‘wp_head’, ‘...’ ) after the do_action( ‘wp_head’ ); hooks has been called, your action won’t ever be fired. Additionally, you can’t use add_action or add_filter functions before they’ve been defined by WordPress. Echoing data in filters This really will cause the world to end Bad or No data returned by filter This is a handshake. Give back what you receive.
  • 28. Common Mistakes Mismatched parameters in remove_* WordCamp Raleigh 2011 If you’re using remove_action or remove_filter, make sure that you’re using the same params used with add_action and add_filter Missing parameters Make sure you’ve used the 4th accepted_args param with add_action or add_filter.
  • 29. Frequently Asked Questions Can I use the hook API outside of WordPress WordCamp Raleigh 2011 Yes. wp-includes/plugin.php & http://backpress.org/ Are there other ʻhooksʻ in the code? Yes. http://codex.wordpress.org/WordPress_API's What if I canʼt find a needed hook Look harder. Check further up the code. http://wordpress.org/news/2009/05/ideas/ Can I remove remove WordPress core hooks? Yes. /wp-includes/default-filters.php Can I add my own hook tags? Yes. I would encourage it.
  • 30. Additional Resources WordCamp Raleigh Online 2011 • http://codex.wordpress.org/Plugin_AP http://codex.wordpress.org/Plugin_API/Filter_Reference • http://codex.wordpress.org/Plugin_API/Action_Reference • http://codex.wordpress.org/Plugin_API/Hooks_2.0.x • http://wpcandy.com/teaches/how-to-use-wordpress-hooks • http://www.nathanrice.net/blog/an-introduction-to-wordpress-action- hooks/ • http://adambrown.info/p/wp_hooks • http://wpengineer.com/1302/define-your-own-wordpress-hooks/ • http://wordpress.org/extend/plugins/wordpress-hook-sniffer/ • http://wp-roadmap.com/demo/ • http://andy.wordpress.com/2008/10/30/wordpress-include-stack/ Offline • Professional WordPress Plugin Development • Professional WordPress • The WordPress Bible
  • 31. WordPress Filters and Actions @glennansley WordCamp Raleigh 2011

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n