Word Press Plugin Development By Nyros Developer

2,654 views

Published on

Word Press Plugin Development

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,654
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
85
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Word Press Plugin Development By Nyros Developer

  1. 1. WordPress Plugin Development Presented By Thirupathi.J
  2. 2. Concepts <ul><li>What is wordpress? </li></ul><ul><li>How to install wordpress? </li></ul><ul><li>What is wordpress plugin? </li></ul><ul><li>What do you need to make a wordpress plugin? </li></ul><ul><li>Plugin Structure? </li></ul><ul><li>Plugin API? </li></ul>
  3. 3. What is WordPress? WordPress is an open source blog publishing application powered by PHP and MySQL which can also be used for content management. It has many features including a workflow, a plugin architecture and a templating system.
  4. 4. How to install WordPress? Download the wordpress latest version from: http://wordpress.org/download/
  5. 5. What is a WordPress plugin? Little applications used to enhance functionality or add specific functions tailored to a site's specific needs.
  6. 6. Some plugins: Capitalize Titles of Pages and Posts WordPress Database Backup WordPress.com Stats Comment Hilite
  7. 7. What do you need to make a plugin? a problem to solve some PHP knowledge some spare time a test server with your test wordpress (XAMPP is good.) ‏
  8. 8. Plugin Directory Structure <ul><li>Your Plugin: </li></ul><ul><ul><li>/wp-content/plugins/my-plugin </li></ul></ul><ul><li>Inside “ my-plugin ” </li></ul><ul><ul><li>readme.txt </li></ul></ul><ul><ul><li>screenshot-1.png </li></ul></ul><ul><ul><li>my-plugin.php </li></ul></ul><ul><li>Always put it in a directory! </li></ul><ul><li>Uses 'dashes' and not 'underscores' </li></ul>http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations
  9. 9. Plugin API - Enabled &quot;hooks&quot; - Extend functionality without editing the core code - Two categories: Actions and Filters
  10. 10. 2 Kinds of WordPress Hooks Actions = “Do Something” Filters = “Transform”
  11. 11. 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. add_action( 'hook_name', 'your_function_name', [priority], [accepted_args] );
  12. 12. Filters Functions that modify text, lists and various types of information that are used and produced by WordPress. add_filter('hook_name', 'your_filter_function', [priority], [accepted_args]);
  13. 13. Writing Your First Plugin
  14. 14. readme.txt <ul><li>http://codex.wordpress.org/Writing_a_Plugin#Readme_File </li></ul><ul><li>http://wordpress.org/extend/plugins/about/readme.txt </li></ul>Useful only for publishing to WordPress Plugin Directory Information about your plugin: Description, Installation, Changelog, Donation Links, Tags, etc...
  15. 15. screenshot-1.png <ul><li>Useful only for publishing to </li></ul><ul><li>WordPress Plugin Directory </li></ul>
  16. 16. my-plugin.php <ul><li>4 parts to a plugin </li></ul><ul><ul><li>Plugin Header </li></ul></ul><ul><ul><li>Hooks </li></ul></ul><ul><ul><li>PHP Code </li></ul></ul><ul><ul><li>Template Code </li></ul></ul>
  17. 17. File Structure
  18. 18. Plugin Headers http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
  19. 19. Plugin Headers http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information <ul><li>Always on top, no choice </li></ul><ul><li>Fill in with your own details </li></ul>
  20. 20. Hooks (Filters)
  21. 21. Hooks (Filters) <ul><li>After plugin headers (my preferance) </li></ul><ul><li>Makes it easier to find </li></ul>
  22. 22. PHP Code
  23. 23. Plugin 1 Figure out what you want to do. I want to convert all instances of “WordPress” to “WORDPRESS”in a post's content.
  24. 24. the_content (filter) http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
  25. 25. add_filter http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
  26. 26. add_filter http://codex.wordpress.org/Plugin_API#Hook_to_WordPress ② ① Hook Name ② Callback ①
  27. 27. Hook Callback <ul><li>Determines what PHP function to call </li></ul><ul><li>Callback can be either: </li></ul><ul><ul><li>String; or </li></ul></ul><ul><ul><li>Array of 2 strings (my preference) </li></ul></ul>
  28. 28. Hook Callback <ul><li>String </li></ul><ul><ul><li>Calls a function </li></ul></ul><ul><li>Array of 2 strings </li></ul><ul><ul><li>Calls a static function in a class </li></ul></ul>
  29. 29. They do the same thing
  30. 30. I Prefer Array Callbacks <ul><li>Allows me to segment my code </li></ul><ul><li>Lower chances of name conflicts </li></ul><ul><li>Easily tell which function belongs to which hook </li></ul>
  31. 31. Filters are Transformations filters have to return a transformation
  32. 32. 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
  33. 34. Plugin 2 Figure out what you want to do. I want to BOLD all instances of “WORDPRESS” in a post's content.
  34. 35. Hook Priority http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
  35. 36. Priority ② ② Callback ① ③ ② ② ③ Priority (optional) ① Hook Name http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
  36. 37. Which one goes first? WordPress2WORDPRESS#the_content ABolderWordPress#the_content
  37. 38. Default Priority 10 smaller numbers = higher priority larger numbers = lower priority http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
  38. 39. Therefore Order of execution: (10) WordPress2WORDPRESS#the_content (20) ABolderWordPress#the_content
  39. 40. THANK YOU

×