SlideShare une entreprise Scribd logo
1  sur  29
Hooked on WordPress
     Actions and Filters
John Dillick
              @johndillick


Core developer on Shopp e-commerce plugin
for WordPress

Developing for and supporting WordPress for
3 years

Technical writer and information sponge.

Not a design guy; Leave graphics and design
to other guys.
Who’s this for?
Desire to extend and customize WordPress

Some PHP knowledge

Not already a WordPress plugin developer, or
just need a place to sit and zone out for 45
minutes.

Don’t mind hearing me say “Um” at least a
thousand times. I’m not a professional
speaker.
WTF are actions/filters

RTFM - see http://codex.wordpress.org/
Plugin_API

Actions are points of execution in WordPress
that your plugin can “hook” code to execute.

Filters give your code an opportunity to add/
remove/modify data before it will be used by
WordPress and other plugins.
What actions/filter are
     out there?
Short answer: Too many to cover in 45
minutes.

Covering some important ones; Dig into codex
and WordPress code itself to discover
amazing possibilities.

Covering what the hooks look like, syntax
stuff, and how to leverage them.
Actions, why?
Devs think, ‘wouldn’t it be nice to have “this”
happen when “that” happens?’

One way to do this: modify WordPress code
directly.
                                    NO!
Actions are provided by the developer of a
particular feature of WordPress to give you an
opportunity to do “something” too.

Often provide you an opportunity to put things
into motion before, during, or after another
action
What does an action
    “hook” look like?

   <?php do_action(‘action_name’); ?>
                 <?php
do_action_ref_array(‘action_name’,$args);
                   ?>
How to hook in:


If the “hook” name in WP is ‘do_this’:

<?php do_action(‘do_this’); ?>

You hook in by providing a “callback” (function
name):

<?php add_action(‘do_this’,‘my_function’); ?>
Callbacks
Quick PHP review, a callback is:

1. String name of a function: ‘funk’
<?php function funk () {} ?>

<?php

//callback

add_action(‘do_something’,‘funk’);
Callbacks, cont.
2. An array with an Object and a string function
name.
<?php

class A {

    function funk () {}

}

$A = new A();

//callback for $A->funk();

add_action( ‘do_something’, array($A,‘funk’) ); ?>
Callbacks, cont.
3. An array with a class name and a string static
function name.
<?php

class B {

     static function funk () {}

}

//callback for B::funk();

add_action( ‘do_something’, array(‘B’,‘funk’) );

?>
Callbacks, cont.
3. Callback returned from a function, such as
create_function()
<?php

// callback for anonymous function

$my_func = create_function(“$args”,”echo ‘hello world!’;”);

add_action( ‘do_something’, $my_func );

?>
add_action()
The full form:

<?php

add_action( $tagname, $callback, $priority,
$argcount );

?>
add_action() cont.

$priority: (Default 10) The smaller the number,
the quicker your function will happen, the
bigger, the later.

$argcount: (Default 1) If the action passes 1 or
more arguments as useful data, you can tell
how many you want passed to your callback.
do_action() example
<?php //your code

add_action(‘hello_set’,’a’,10,1);

add_action(‘hello_set’,’b’,1);

function a ( &$hello ) { $hello = ‘hola, el mundo’; }

function b () { exit(); } ?>

<?php

// Primitive action hook, pretend it’s in WordPress

$hello = ‘hello world’;

do_action(‘hello_set’, $hello);

echo $hello;

?>
What output?
Answer: Nothing

Because function ‘b’ was called with a higher
priority, and exited, ‘a’ never ran... nor anything
else afterwards.

All plugins have an opportunity to break all other
plugins at some point.

Use standard WordPress function calls whenever
possible.
Filtering

WordPress is using some data to do
something, for instance, to output the body of
a post on my blog.

As a developer, I want to be able to add,
remove, or modify that data before WordPress
uses it.
How to filter:

If the “filter” tag name in WP is ‘the_content’:

<?php apply_filters(‘the_content’,$postcontent); ?>

You hook in by providing a “callback”, just like with
actions hooks.

<?php add_filter(‘the_content’,‘my_function’); ?>

my_function will always expect at least one arg,
and will always return an arg.
Full filter syntax

add_filter($tagname, $callback, $priority,
$num_of_args);

Your filter is expected to return something.

Forgetting to return something will certainly
break something.
Wordpress with ‘P’!
Back in 2010, WordPress decided to take
measures to ensure the WordPress trademark was
used properly.
<?php

add_filter(‘the_content’,‘capital_P_dangit’);

add_filter(‘the_title’,‘capital_P_dangit’);

add_filter(‘comment_text’,‘capital_P_dangit’);

?>
If I had core commit...
... you would all know.
<?php

function john_dillick_rocks ( $content ) {

!    $content = str_replace(‘Dillick sucks’,‘Dillick rocks’,$content);

!    return $content . ‘ - BTW, you know John Dillick rocks, right?’;

}

add_filter(‘the_content’,‘john_dillick_rocks’);

add_filter(‘the_title’,‘john_dillick_rocks’);

add_filter(‘comment_text’,‘john_dillick_rocks’);

?>
Removing Action/Filter
remove_action($tag,$callback,$priority,$nargs);

remove_filter($tag,$callback,$priority,$nargs);

remove_all_actions($tag,$priority);

remove_all_filters($tag,$priority);
<?php

foreach ( array(‘the_content’,‘the_title’,‘comment_text’) as $tag ) {

!   remove_action($tag,’capital_P_dangit’);

!   // remove_action($tag,‘john_dillick_rocks’);

}
Check for an action/filter
has_action($tag,$callback);

has_filter($tag,$callback);
<?php

function enlightened () {

!    if ( has_filter(‘the_content’,‘john_dillick_rocks’) )

!    !   echo “<p>This site powered by Sasquatch.</p>”;

!    else echo “<p>Nothing to see here. Move along.</p>”;

}

add_action(‘wp_footer’,’enlightened’);

?>
Common Actions

add_action(‘init’,$callback);
Early action for plugin initialization.

add_action(‘admin_init’,$callback);
Called on admin initialization.
Common Actions
add_action(‘wp_head’,$callback);

Called in theme when page header is output.


add_action(‘admin_head’,$callback);
Called in admin when page header is output.

add_action(‘wp_footer’,$callback);
Called in theme when page footer is output.

add_action(‘admin_footer’,$callback);
Called in admin when page footer is output.
Action Reference


http://codex.wordpress.org/Plugin_API/
Action_Reference
Common Filters

add_filter(‘the_content’,$callback);
Filters post and page content.

add_filter(‘the_excerpt’,$callback);
Filters post and page excerpt content.
Common Filters

add_filter(‘the_title’,$callback);
Filters post and page content titles.

add_filter(‘wp_title’,$callback);
Filters blog page title.
Filters Reference


http://codex.wordpress.org/Plugin_API/
Filter_Reference

Contenu connexe

Tendances

The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13
Stephan Hochdörfer
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012
l3rady
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
phelios
 
How does get template part works in twenty ten theme
How does get template part works in twenty ten themeHow does get template part works in twenty ten theme
How does get template part works in twenty ten theme
mohd rozani abd ghani
 

Tendances (20)

Building a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing StrategiesBuilding a Pyramid: Symfony Testing Strategies
Building a Pyramid: Symfony Testing Strategies
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
 
Django a whirlwind tour
Django   a whirlwind tourDjango   a whirlwind tour
Django a whirlwind tour
 
Spiffy Applications With JavaScript
Spiffy Applications With JavaScriptSpiffy Applications With JavaScript
Spiffy Applications With JavaScript
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Extending Twig
Extending TwigExtending Twig
Extending Twig
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012You don’t know query - WordCamp UK Edinburgh 2012
You don’t know query - WordCamp UK Edinburgh 2012
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)
 
New in php 7
New in php 7New in php 7
New in php 7
 
How does get template part works in twenty ten theme
How does get template part works in twenty ten themeHow does get template part works in twenty ten theme
How does get template part works in twenty ten theme
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
 

Similaire à Actions filters

Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 

Similaire à Actions filters (20)

Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
09 Oo Php Register
09 Oo Php Register09 Oo Php Register
09 Oo Php Register
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
WordPress Plugin Basics
WordPress Plugin BasicsWordPress Plugin Basics
WordPress Plugin Basics
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)Best Practices in Plugin Development (WordCamp Seattle)
Best Practices in Plugin Development (WordCamp Seattle)
 
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)
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
How I Became a WordPress Hacker
How I Became a WordPress HackerHow I Became a WordPress Hacker
How I Became a WordPress Hacker
 
WordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcodeWordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcode
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 
PHP-03-Functions.ppt
PHP-03-Functions.pptPHP-03-Functions.ppt
PHP-03-Functions.ppt
 

Dernier

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
Safe Software
 
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
panagenda
 

Dernier (20)

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
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Actions filters

  • 1. Hooked on WordPress Actions and Filters
  • 2. John Dillick @johndillick Core developer on Shopp e-commerce plugin for WordPress Developing for and supporting WordPress for 3 years Technical writer and information sponge. Not a design guy; Leave graphics and design to other guys.
  • 3. Who’s this for? Desire to extend and customize WordPress Some PHP knowledge Not already a WordPress plugin developer, or just need a place to sit and zone out for 45 minutes. Don’t mind hearing me say “Um” at least a thousand times. I’m not a professional speaker.
  • 4. WTF are actions/filters RTFM - see http://codex.wordpress.org/ Plugin_API Actions are points of execution in WordPress that your plugin can “hook” code to execute. Filters give your code an opportunity to add/ remove/modify data before it will be used by WordPress and other plugins.
  • 5. What actions/filter are out there? Short answer: Too many to cover in 45 minutes. Covering some important ones; Dig into codex and WordPress code itself to discover amazing possibilities. Covering what the hooks look like, syntax stuff, and how to leverage them.
  • 6. Actions, why? Devs think, ‘wouldn’t it be nice to have “this” happen when “that” happens?’ One way to do this: modify WordPress code directly. NO! Actions are provided by the developer of a particular feature of WordPress to give you an opportunity to do “something” too. Often provide you an opportunity to put things into motion before, during, or after another action
  • 7. What does an action “hook” look like? <?php do_action(‘action_name’); ?> <?php do_action_ref_array(‘action_name’,$args); ?>
  • 8. How to hook in: If the “hook” name in WP is ‘do_this’: <?php do_action(‘do_this’); ?> You hook in by providing a “callback” (function name): <?php add_action(‘do_this’,‘my_function’); ?>
  • 9. Callbacks Quick PHP review, a callback is: 1. String name of a function: ‘funk’ <?php function funk () {} ?> <?php //callback add_action(‘do_something’,‘funk’);
  • 10. Callbacks, cont. 2. An array with an Object and a string function name. <?php class A { function funk () {} } $A = new A(); //callback for $A->funk(); add_action( ‘do_something’, array($A,‘funk’) ); ?>
  • 11. Callbacks, cont. 3. An array with a class name and a string static function name. <?php class B { static function funk () {} } //callback for B::funk(); add_action( ‘do_something’, array(‘B’,‘funk’) ); ?>
  • 12. Callbacks, cont. 3. Callback returned from a function, such as create_function() <?php // callback for anonymous function $my_func = create_function(“$args”,”echo ‘hello world!’;”); add_action( ‘do_something’, $my_func ); ?>
  • 13. add_action() The full form: <?php add_action( $tagname, $callback, $priority, $argcount ); ?>
  • 14. add_action() cont. $priority: (Default 10) The smaller the number, the quicker your function will happen, the bigger, the later. $argcount: (Default 1) If the action passes 1 or more arguments as useful data, you can tell how many you want passed to your callback.
  • 15. do_action() example <?php //your code add_action(‘hello_set’,’a’,10,1); add_action(‘hello_set’,’b’,1); function a ( &$hello ) { $hello = ‘hola, el mundo’; } function b () { exit(); } ?> <?php // Primitive action hook, pretend it’s in WordPress $hello = ‘hello world’; do_action(‘hello_set’, $hello); echo $hello; ?>
  • 16. What output? Answer: Nothing Because function ‘b’ was called with a higher priority, and exited, ‘a’ never ran... nor anything else afterwards. All plugins have an opportunity to break all other plugins at some point. Use standard WordPress function calls whenever possible.
  • 17. Filtering WordPress is using some data to do something, for instance, to output the body of a post on my blog. As a developer, I want to be able to add, remove, or modify that data before WordPress uses it.
  • 18. How to filter: If the “filter” tag name in WP is ‘the_content’: <?php apply_filters(‘the_content’,$postcontent); ?> You hook in by providing a “callback”, just like with actions hooks. <?php add_filter(‘the_content’,‘my_function’); ?> my_function will always expect at least one arg, and will always return an arg.
  • 19. Full filter syntax add_filter($tagname, $callback, $priority, $num_of_args); Your filter is expected to return something. Forgetting to return something will certainly break something.
  • 20. Wordpress with ‘P’! Back in 2010, WordPress decided to take measures to ensure the WordPress trademark was used properly. <?php add_filter(‘the_content’,‘capital_P_dangit’); add_filter(‘the_title’,‘capital_P_dangit’); add_filter(‘comment_text’,‘capital_P_dangit’); ?>
  • 21. If I had core commit... ... you would all know. <?php function john_dillick_rocks ( $content ) { ! $content = str_replace(‘Dillick sucks’,‘Dillick rocks’,$content); ! return $content . ‘ - BTW, you know John Dillick rocks, right?’; } add_filter(‘the_content’,‘john_dillick_rocks’); add_filter(‘the_title’,‘john_dillick_rocks’); add_filter(‘comment_text’,‘john_dillick_rocks’); ?>
  • 22. Removing Action/Filter remove_action($tag,$callback,$priority,$nargs); remove_filter($tag,$callback,$priority,$nargs); remove_all_actions($tag,$priority); remove_all_filters($tag,$priority); <?php foreach ( array(‘the_content’,‘the_title’,‘comment_text’) as $tag ) { ! remove_action($tag,’capital_P_dangit’); ! // remove_action($tag,‘john_dillick_rocks’); }
  • 23. Check for an action/filter has_action($tag,$callback); has_filter($tag,$callback); <?php function enlightened () { ! if ( has_filter(‘the_content’,‘john_dillick_rocks’) ) ! ! echo “<p>This site powered by Sasquatch.</p>”; ! else echo “<p>Nothing to see here. Move along.</p>”; } add_action(‘wp_footer’,’enlightened’); ?>
  • 24. Common Actions add_action(‘init’,$callback); Early action for plugin initialization. add_action(‘admin_init’,$callback); Called on admin initialization.
  • 25. Common Actions add_action(‘wp_head’,$callback); Called in theme when page header is output. add_action(‘admin_head’,$callback); Called in admin when page header is output. add_action(‘wp_footer’,$callback); Called in theme when page footer is output. add_action(‘admin_footer’,$callback); Called in admin when page footer is output.
  • 27. Common Filters add_filter(‘the_content’,$callback); Filters post and page content. add_filter(‘the_excerpt’,$callback); Filters post and page excerpt content.
  • 28. Common Filters add_filter(‘the_title’,$callback); Filters post and page content titles. add_filter(‘wp_title’,$callback); Filters blog page title.

Notes de l'éditeur

  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