Beginning WordPress Plugin Development Aizat Faiz aizat.faiz@gmail.com
Download and view at http://blog.aizatto.com/?p=3729
Creative Commons http://www.flickr.com/photos/kwl/4435490471/
By Attribution http://www.flickr.com/photos/balakov/4571468943/
Aizat Faiz http://www.flickr.com/photos/byte/3397174843/ [email_address]
Your Friends / Resources http://www.flickr.com/photos/balakov/4571468943/
WordPress Codex <ul>http://codex.wordpress.org </ul>
WordPress Plugin Directory
Google <ul>http://www.google.com.my </ul>
What is a Hook? http://www.flickr.com/photos/kwl/4247555680/
WordPress is the Base http://www.flickr.com/photos/kwl/4247555680/
Plugins are the Blocks http://www.flickr.com/photos/sixteen-miles/3757674953/
Hooks are the Pegs http://www.flickr.com/photos/linuxmatt/92802487/
Actions Filters 2 Kinds of WordPress Hooks
Actions
Actions Actions are the hooks that the WordPress core launches at specific points during execution, or when specific event...
Actions Actions = “Do Something”
Filters
Filters Filters are functions that WordPress passes data through, at certain points in execution, just before taking some ...
Filters Filters = Transform
Actions and Filters Actions = “Do Something” Filters = Transform
 
1133
1133 hooks <ul>* as of WordPress v2.9 </ul>
Problem: Finding the Right Hook for the Right Job
Hard to Recommend <ul><li>Look at the resources I gave you </li><ul><li>WordPress Codex
WordPress Plugin Directory
Google </li></ul><li>Action and Filter Reference </li><ul><li>http://codex.wordpress.org/Plugin_API/Action_Reference
http://codex.wordpress.org/Plugin_API/Filter_Reference </li></ul></ul>
 
Writing Your First Plugin
WordPress Directory Structure All Plugins are stored in: /wp-content/plugins/
Plugin Directory Structure <ul><li>Your Plugin: </li><ul><li>/wp-content/plugins/my-plugin </li></ul><li>Inside “ my-plugi...
screenshot-1.png
my-plugin.php </li></ul><li>Always put it in a directory!
Uses 'dashes' and not 'underscores' </li></ul>http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations
readme.txt http://codex.wordpress.org/Writing_a_Plugin#Readme_File http://wordpress.org/extend/plugins/about/readme.txt Us...
screenshot-1.png Useful only for publishing to WordPress Plugin Directory
my-plugin.php Your Plugin Code <ul><li>4 parts to a plugin </li><ul><li>Plugin Header
Hooks
PHP Code
Template Code </li></ul></ul>
File Structure
Plugin Headers http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
Plugin Headers http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information <ul><li>Always on top, no choice
Fill in with your own details </li></ul>
Hooks (Filters)
Hooks (Filters) <ul><li>After plugin headers (my preferance)
Makes it easier to find </li></ul>
PHP Code
 
Plugin 1 Figure out what you want to do. I want to convert all instances of “WordPress” to “WORDPRESS” in a post's content.
the_content  (filter) http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
add_filter http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
add_filter http://codex.wordpress.org/Plugin_API#Hook_to_WordPress ② ①   Hook Name ②  Callback ①
Hook Callback <ul><li>Determines what PHP function to call
Callback can be either: </li><ul><li>String; or
Array of 2 strings (my preference) </li></ul></ul>
Hook Callback <ul><li>String </li><ul><li>Calls a function </li></ul><li>Array of 2 strings </li><ul><li>Calls a static fu...
They do the same thing
I Prefer Array Callbacks <ul><li>Allows me to segment my code
Lower chances of name conflicts
Easily tell which function belongs to which hook </li></ul>
Filters are Transformations filters have to return a transformation
Filter  return  Values <ul><li>A filters return value, is the result of the transformation </li></ul>② ①   return ②  trans...
 
Plugin 2 Figure out what you want to do. I want to  BOLD all instances of “WORDPRESS” in a post's content.
Hook Priority http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Priority ② ②  Callback ① ③ ② ② ③   Priority  (optional) ①   Hook Name http://codex.wordpress.org/Plugin_API#Hook_to_WordPr...
Which one goes first? WordPress2WORDPRESS#the_content ABolderWordPress#the_content
Default Priority 10 smaller numbers = higher priority larger numbers = lower priority http://codex.wordpress.org/Plugin_AP...
Therefore Order of execution: (10)   WordPress2WORDPRESS#the_content (20)   ABolderWordPress#the_content
 
Plugin 3 Figure out what you want to do. I want to add a class, to represent a post that has more than 10 comments
accepted_args http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Upcoming SlideShare
Loading in...5
×

Beginning WordPress Plugin Development

16,787

Published on

Presented at WordCamp Malaysia 2010.

Slideshare also does not resize my cropped images properly, thus resulting in squished images. This is noticeable on my squished code.

Published in: Technology, Business
1 Comment
9 Likes
Statistics
Notes
No Downloads
Views
Total Views
16,787
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
179
Comments
1
Likes
9
Embeds 0
No embeds

No notes for slide
  • The reason we all use WordPress, is because its free.
  • My slides are also free. Free to use. Free to modify. Free to redistribute.
  • Head developer at UrekaLabs Create Web applications on Ruby on Rails and PHP Used to do swing dancing, but stopped a year ago, and have massively gained weight
  • When developing WordPress plugins, there are several friends you need to know
  • Dirth of information available here Lots of information about everything
  • Sometimes its not enough The WordPress Codex may not be enough
  • You are not going to need to know all You are probably only going to use one or two of them
  • You are not going to need to know all You are probably only going to use one or two of them
  • There are so many hooks, which one do we need to use? Figure out what you want to do Go through the plugin Action and Filter Reference
  • Transcript of "Beginning WordPress Plugin Development"

    1. 1. Beginning WordPress Plugin Development Aizat Faiz aizat.faiz@gmail.com
    2. 2. Download and view at http://blog.aizatto.com/?p=3729
    3. 3. Creative Commons http://www.flickr.com/photos/kwl/4435490471/
    4. 4. By Attribution http://www.flickr.com/photos/balakov/4571468943/
    5. 5. Aizat Faiz http://www.flickr.com/photos/byte/3397174843/ [email_address]
    6. 6. Your Friends / Resources http://www.flickr.com/photos/balakov/4571468943/
    7. 7. WordPress Codex <ul>http://codex.wordpress.org </ul>
    8. 8. WordPress Plugin Directory
    9. 9. Google <ul>http://www.google.com.my </ul>
    10. 10. What is a Hook? http://www.flickr.com/photos/kwl/4247555680/
    11. 11. WordPress is the Base http://www.flickr.com/photos/kwl/4247555680/
    12. 12. Plugins are the Blocks http://www.flickr.com/photos/sixteen-miles/3757674953/
    13. 13. Hooks are the Pegs http://www.flickr.com/photos/linuxmatt/92802487/
    14. 14. Actions Filters 2 Kinds of WordPress Hooks
    15. 15. Actions
    16. 16. Actions Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API. <ul>http://codex.wordpress.org/Plugin_API#Actions </ul>http://codex.wordpress.org/Plugin_API/Action_Reference
    17. 17. Actions Actions = “Do Something”
    18. 18. Filters
    19. 19. Filters Filters are functions that WordPress passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or sending it to the browser screen). Filters sit between the database and the browser (when WordPress is generating pages), and between the browser and the database (when WordPress is adding new posts and comments to the database); most input and output in WordPress passes through at least one filter. WordPress does some filtering by default, and your plugin can add its own filtering http://codex.wordpress.org/Plugin_API#Filters http://codex.wordpress.org/Plugin_API/Filter_Reference
    20. 20. Filters Filters = Transform
    21. 21. Actions and Filters Actions = “Do Something” Filters = Transform
    22. 23. 1133
    23. 24. 1133 hooks <ul>* as of WordPress v2.9 </ul>
    24. 25. Problem: Finding the Right Hook for the Right Job
    25. 26. Hard to Recommend <ul><li>Look at the resources I gave you </li><ul><li>WordPress Codex
    26. 27. WordPress Plugin Directory
    27. 28. Google </li></ul><li>Action and Filter Reference </li><ul><li>http://codex.wordpress.org/Plugin_API/Action_Reference
    28. 29. http://codex.wordpress.org/Plugin_API/Filter_Reference </li></ul></ul>
    29. 31. Writing Your First Plugin
    30. 32. WordPress Directory Structure All Plugins are stored in: /wp-content/plugins/
    31. 33. Plugin Directory Structure <ul><li>Your Plugin: </li><ul><li>/wp-content/plugins/my-plugin </li></ul><li>Inside “ my-plugin ” </li><ul><li>readme.txt
    32. 34. screenshot-1.png
    33. 35. my-plugin.php </li></ul><li>Always put it in a directory!
    34. 36. Uses 'dashes' and not 'underscores' </li></ul>http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations
    35. 37. readme.txt http://codex.wordpress.org/Writing_a_Plugin#Readme_File http://wordpress.org/extend/plugins/about/readme.txt Useful only for publishing to WordPress Plugin Directory Information about your plugin: Description, Installation, Changelog, Donation Links, Tags, etc...
    36. 38. screenshot-1.png Useful only for publishing to WordPress Plugin Directory
    37. 39. my-plugin.php Your Plugin Code <ul><li>4 parts to a plugin </li><ul><li>Plugin Header
    38. 40. Hooks
    39. 41. PHP Code
    40. 42. Template Code </li></ul></ul>
    41. 43. File Structure
    42. 44. Plugin Headers http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
    43. 45. Plugin Headers http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information <ul><li>Always on top, no choice
    44. 46. Fill in with your own details </li></ul>
    45. 47. Hooks (Filters)
    46. 48. Hooks (Filters) <ul><li>After plugin headers (my preferance)
    47. 49. Makes it easier to find </li></ul>
    48. 50. PHP Code
    49. 52. Plugin 1 Figure out what you want to do. I want to convert all instances of “WordPress” to “WORDPRESS” in a post's content.
    50. 53. the_content (filter) http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
    51. 54. add_filter http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
    52. 55. add_filter http://codex.wordpress.org/Plugin_API#Hook_to_WordPress ② ① Hook Name ② Callback ①
    53. 56. Hook Callback <ul><li>Determines what PHP function to call
    54. 57. Callback can be either: </li><ul><li>String; or
    55. 58. Array of 2 strings (my preference) </li></ul></ul>
    56. 59. Hook Callback <ul><li>String </li><ul><li>Calls a function </li></ul><li>Array of 2 strings </li><ul><li>Calls a static function in a class </li></ul></ul>
    57. 60. They do the same thing
    58. 61. I Prefer Array Callbacks <ul><li>Allows me to segment my code
    59. 62. Lower chances of name conflicts
    60. 63. Easily tell which function belongs to which hook </li></ul>
    61. 64. Filters are Transformations filters have to return a transformation
    62. 65. Filter return Values <ul><li>A filters return value, is the result of the transformation </li></ul>② ① return ② transformation ① http://php.net/manual/en/function.preg-replace.php
    63. 67. Plugin 2 Figure out what you want to do. I want to BOLD all instances of “WORDPRESS” in a post's content.
    64. 68. Hook Priority http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
    65. 69. Priority ② ② Callback ① ③ ② ② ③ Priority (optional) ① Hook Name http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
    66. 70. Which one goes first? WordPress2WORDPRESS#the_content ABolderWordPress#the_content
    67. 71. Default Priority 10 smaller numbers = higher priority larger numbers = lower priority http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
    68. 72. Therefore Order of execution: (10) WordPress2WORDPRESS#the_content (20) ABolderWordPress#the_content
    69. 74. Plugin 3 Figure out what you want to do. I want to add a class, to represent a post that has more than 10 comments
    70. 75. accepted_args http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
    71. 76. accepted_args http://codex.wordpress.org/Plugin_API#Hook_to_WordPress ① ③ ② ④ accepted args (optional) ① Hook Name ② Callback ④ ③ Priority
    72. 77. accepted_args Number of arguments for the filter
    73. 79. Plugin 4 Figure out what you want to do. I want to add a custom stylesheet
    74. 80. init (action) http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
    75. 81. wp_enqueue_style ① ③ ② ① WordPress function ② Style ID ③ Style URL http://codex.wordpress.org/Function_Reference/wp_enqueue_style
    76. 82. Actions “Do Something” Actions do not need to return anything
    77. 84. Actions Filters 2 Kinds of WordPress Hooks
    78. 85. Actions Actions = “Do Something”
    79. 86. Filters Filters = Transform
    80. 87. Actions and Filters Actions = “Do Something” Filters = Transform
    81. 89. MOAR KITTEHS
    82. 90. Beginning WordPress Plugin Development Aizat Faiz [email_address] http://blog.aizatto.com/?p=3729 kthxbai
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×