Writing Extensible
Plugins in
WordPress
#WCTO2013
Imran Nathani
 What I do?:
Team lead at Shaw Media for GlobalNews.ca

About Me

 Past Experience:
For 6 yrs I have been ...
Usability

Extensibility
is not
Usability

Extensibility

 Target audience :
All WordPress users

 Target audience:
Deve...
What is an
extensible
plugin?

A plugin that can be
modified and extended
beyond its original purpose
by another plugin or...
Why write
an
extensible
plugin?

 Saves time
 Increases code portability
 Makes extra money $-)

 Reduces documentatio...
Helper
functions

 “Helps” re-use code
 “Helps” make code easier to read
Hooks
Traditional function call

What are
hooks ?
Wordpress Hook call

What are
hooks ?
Wordpress hook call ( Multiple )

What are
hooks ?
What are
hooks ?

Hooks are placeholders
for code.
Action hook

Filter hook

 Extending methods

 Extend values

 Returns nothing

 Returns a value

do_action( … )

appl...
Action
hook

Wherever an action hook
is placed, it will execute
any code that has been
“hooked” to it.
Usage A :
do_action( ‘hook-name’ );

Action
hook
usage

Usage B:
do_action( ‘hook-name’ , $arg1, $arg2, … );
Usage C:
do_a...
Utility functions
 add_action(..)

Actions

 remove_action(..)
 remove_all_actions(..)
 has_action(..)
 did_action(.....
Action placements
Actions

 Before a task
 After a task
 Append mark up
Core actions
 publish_post

Actions

 save_post

 wp_head
 wp_foot
Actions
DEMO
Filter
hooks

Wherever a filter hook is
placed, it will manipulate
any value that has been
passed into with the
function “...
Usage A :

Filter
hook
usage

$value = apply_filters( ‘hook-name’ , $value )
Usage B :

$value = apply_filters( ‘hook-name...
Utility functions
 add_filter(…)

Filters

 remove_filter(…)
 remove_all_filters(...)
 has_filter(…)
 current_filter(...
Filter placements
Filters

 Before using values
 Before value set up
 Before returning values
Core filters
Filters

 the_title
 the_excerpt

 post_link
 the_date
Filters
DEMO
Improve efficiency
Tips
&
Tricks
Improve efficiency
Tips
&
Tricks
Prefix hook names
Tips
&
Tricks
Do not over extend!

Tips
&
Tricks
Validate returns
Tips
&
Tricks
Combine Filters
Tips
&
Tricks
Combine Filters
Tips
&
Tricks
Localize scripts with Filters
Tips
&
Tricks
Localize scripts with Filters
Tips
&
Tricks
Good
reads

Wordpress Codex ( How to? )
Wordpress Core ( Why to? )
Questions?
Upcoming SlideShare
Loading in …5
×

Writing extensible plugins

2,076 views
1,872 views

Published on

Wordcamp Toronto 2013 #WCTO2013

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,076
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • => What are the traditional methods to extend code?
  • Isn’t this how functions work?
  • Isn’t this how functions work?
  • Isn’t this how functions work?
  • Writing extensible plugins

    1. 1. Writing Extensible Plugins in WordPress #WCTO2013
    2. 2. Imran Nathani  What I do?: Team lead at Shaw Media for GlobalNews.ca About Me  Past Experience: For 6 yrs I have been developing print and broadcast news websites. Of which 4 years, I have spent exclusively developing on WordPress VIP.
    3. 3. Usability Extensibility is not Usability Extensibility  Target audience : All WordPress users  Target audience: Developers  Expectations: Options Page, Shortcodes, Widgets etc.  Expectations: ?????
    4. 4. What is an extensible plugin? A plugin that can be modified and extended beyond its original purpose by another plugin or theme without modifying original plugin.
    5. 5. Why write an extensible plugin?  Saves time  Increases code portability  Makes extra money $-)  Reduces documentation
    6. 6. Helper functions  “Helps” re-use code  “Helps” make code easier to read
    7. 7. Hooks
    8. 8. Traditional function call What are hooks ?
    9. 9. Wordpress Hook call What are hooks ?
    10. 10. Wordpress hook call ( Multiple ) What are hooks ?
    11. 11. What are hooks ? Hooks are placeholders for code.
    12. 12. Action hook Filter hook  Extending methods  Extend values  Returns nothing  Returns a value do_action( … ) apply_filters( … ) Types of hooks
    13. 13. Action hook Wherever an action hook is placed, it will execute any code that has been “hooked” to it.
    14. 14. Usage A : do_action( ‘hook-name’ ); Action hook usage Usage B: do_action( ‘hook-name’ , $arg1, $arg2, … ); Usage C: do_action_ref_array( ‘hook-name’ , $array );
    15. 15. Utility functions  add_action(..) Actions  remove_action(..)  remove_all_actions(..)  has_action(..)  did_action(..)
    16. 16. Action placements Actions  Before a task  After a task  Append mark up
    17. 17. Core actions  publish_post Actions  save_post  wp_head  wp_foot
    18. 18. Actions DEMO
    19. 19. Filter hooks Wherever a filter hook is placed, it will manipulate any value that has been passed into with the function “hooked” to it
    20. 20. Usage A : Filter hook usage $value = apply_filters( ‘hook-name’ , $value ) Usage B : $value = apply_filters( ‘hook-name’ , $value, $args, .. )
    21. 21. Utility functions  add_filter(…) Filters  remove_filter(…)  remove_all_filters(...)  has_filter(…)  current_filter( … )
    22. 22. Filter placements Filters  Before using values  Before value set up  Before returning values
    23. 23. Core filters Filters  the_title  the_excerpt  post_link  the_date
    24. 24. Filters DEMO
    25. 25. Improve efficiency Tips & Tricks
    26. 26. Improve efficiency Tips & Tricks
    27. 27. Prefix hook names Tips & Tricks
    28. 28. Do not over extend! Tips & Tricks
    29. 29. Validate returns Tips & Tricks
    30. 30. Combine Filters Tips & Tricks
    31. 31. Combine Filters Tips & Tricks
    32. 32. Localize scripts with Filters Tips & Tricks
    33. 33. Localize scripts with Filters Tips & Tricks
    34. 34. Good reads Wordpress Codex ( How to? ) Wordpress Core ( Why to? )
    35. 35. Questions?

    ×