WordPress Plugin Development For Beginners

4,017 views

Published on

My presentation from WordPress DC 11/9/10

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

No Downloads
Views
Total views
4,017
On SlideShare
0
From Embeds
0
Number of Embeds
52
Actions
Shares
0
Downloads
77
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

WordPress Plugin Development For Beginners

  1. 1. WordPress Plugin Development for Beginners John P. Bloch Senior Web Developer Avendi Media, Inc. http://www.johnpbloch.com/ @johnpbloch
  2. 2. What Are Plugins?  The stupid answer:  Anything you want*  *theoretically, at least  The useful answer:  Non-essential and elective aspects of any given WordPress installation
  3. 3. Wait a Minute... Aren't plugins just extensions of WordPress? Don't they just add functionality that isn't there?
  4. 4. Plugins are Part of WordPress  Plugins have primacy of place  Plugins interact with WordPress in the same way WordPress interacts with itself
  5. 5. An Example Plugin
  6. 6. How Do Plugins Work?  Almost all plugin use hooks. There are two kinds of hooks:  Actions  Filters  What's the difference?  Filters expect you to return something, and...  … that's it!  Hooks let you tell WordPress to execute a function when the specified hook fires
  7. 7. How To Use Hooks  Filters:  <?php add_filter( 'filter_name', 'function_name' ); ?>  Actions:  <?php add_action( 'action_name', 'func_name' ); ?>  Both functions take two optional arguments:  Priority  Accepted Arguments
  8. 8. How To Fire Hooks  To fire an action:  <?php do_action( 'action_name' ); ?>  This fires all functions hooked into that action  To fire a filter:  <?php apply_filters( 'filter_name', 'Filter value' ); ?>  The 'Filter value' will be the first argument of each hooked function  apply_filters will return the filtered input
  9. 9. How Does Priority Work? Actions and filters are executed in the order they are added. So this code will echo: First Second Third
  10. 10. How Does Priority Work? Priority changes this order. Actions and filters have a default priority of 10. Using a lower number gives it higher priority. This code ouputs: Third First Second
  11. 11. Accepted Arguments  Accepted arguments allows you to specify how many arguments to send to a hooked function  Defaults to 1 for both actions and filters  The following would output: Don't mention Joomla Don't mention
  12. 12. Some Common Hooks  Actions  init  template_redirect  admin_init  after_setup_theme  wp_loaded  wp_head  wp_footer  admin_menu  Filters  the_content  the_title  wp_title  template_include  body_class  post_class
  13. 13. But Wait! There's More!  One more way to hook into WordPress is through shortcodes  Shortcodes are inserted into a post or page from the editor; WordPress replaces the shortcode tags with dynamically generated content  Shortcodes are kind of like HTML:  [foo bar='bar']  [foo bar='bar']Some Content[/foo]
  14. 14. How to Add a Shortcode  Shortcodes must be registered:  <?php add_shortcode( 'tag_name', 'function_name' ); ?>  Shortcode handlers take two optional arguments:  Arguments: an array of arguments from the shortcode  Content: the content (if any) of the shortcode  Shortcode handlers should return, not echo, their content
  15. 15. An Example of a Shortcode
  16. 16. Developer Toolbox  Local development environment  LAMPP Stack (XAMPP – http://apachefriends.org)  Subversion  Windows: TortoiseSVN or Cygwin  Everything else: CLI  Text Editor  FTP client  Mac: Transmit  SSH Client  Windows: Putty  Reference  PHPXref (http://www.phpxref.com)
  17. 17. WordPress Developer Toolbox  Official Support Channels  WordPress Codex (http://codex.wordpress.org/)  WordPress Forums (http://wordpress.org/support/)  IRC Channel #wordpress (chat.freenode.net)  Mailing Lists (sort of) (http://codex.wordpress.org/Mailing_Lists)  Unofficial Support Channels  WordPress Answers (http://wordpress.stackexchange.com/)  WordPress Docs (http://wpdocs.labs.thedextrousweb.com/)  Alot of Books
  18. 18. Just Because
  19. 19. Adding Your Plugin to the Directory  http://wordpress.org/extend/plugins/add/  Answer a few questions  Name – Very important! This will determine the name of the directory your plugin creates  Description  Plugin URL (optional)  … And wait!
  20. 20. What is SVN? SVN, or Subversion, is a version control program. Others include Git and Mercurial. Subversion is used for core WordPress development/distribution and official plugin development/distribution. Once you have your repository, anybody in the world can check it out. Only you* can check files into it. *Technically, Nacin and some others have global plugin repo commit access. #blamenacin
  21. 21. How to Use SVN  If you are on windows and use TortoiseSVN, just follow these next steps substituting ”Click X menu item” for ”Execute X command”  Go to the directory into which you'd like the repo to go:  ~$ cd Documents/svn  Check out your repository for the first time:  ~$ svn co http://plugins.svn.wordpress.org/custom-post-permalinks/ custom-post-permalinks  Edit to your heart's content
  22. 22. How to Use SVN  When you're done making changes (or reach a good stopping point), commit your changes:  ~$ svn ci -m 'This is a description of the commit!'  … Tada!
  23. 23. Some Other Notes on SVN  Updating your plugin  Tagging vs. Stable Trunk  Branching  Adding committers (and other admin tools)
  24. 24. Further Reading  Core.  Core.  Core.  Seriously. Just read core's runtime execution.  Line by line.
  25. 25. Now Let's Get Down to Business! Time to switch gears, open VIM, and write a plugin!

×