How To Write a WordPress Plugin

1,032 views

Published on

Quick and basic presentation about how to get started writing WordPres

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

No Downloads
Views
Total views
1,032
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • How To Write a WordPress Plugin

    1. 1. How to Write aWordPress PluginBaltimore WordPress Meetup • September 19, 2011
    2. 2. What is a plugin?Written in PHP Adds functionality without affecting core code Plugin API
    3. 3. Hooks: Actions & Filters
    4. 4. ActionsHey, WP! I’d like to do this when you do that...Calls a function that performs an action, possibly with some data given by WP
    5. 5. Actionsadd_action( $hook_name, $function ); add_action(‘wp_head’, ‘my_custom_js’);add_action(‘wp_head’, array( $some_object, ‘my_custom_js_method’)));
    6. 6. Actionsinit wp_head save_post
    7. 7. FiltersHey, WP! I’d like to change avalue that you’re returning/ using...Calls a function that returns a final
    8. 8. Filtersadd_filter( $hook_name, $function );add_filter(‘the_content’, ‘my_content_filter’);add_filter(‘the_content’, array( $some_object, ‘my_content_method)));
    9. 9. Filtersthe_title the_content wp_email_from
    10. 10. Getting StartedPHP file or foldercontaining PHP file Javascript, CSS, etc. /wp-content/
    11. 11. Plugin Information<?php/*Plugin Name: My Simple PluginPlugin URI: http://theandystratton.com/my-pluginDescription: Does something awesome.Version: 1.0Author: theandystrattonAuthor URI: http://theandystratton.comLicense: GPL2*/
    12. 12. Info Shows in Admin UI
    13. 13. Don’t Just Drop CodeWordPress includes plugins while initializingCoding without hooking into actions/filters = explosion
    14. 14. Starting to CodeWhat do you want to do?I want to add my personal signature to all posts.
    15. 15. Starting to CodeWhat does my plugin do? Filter the content of all posts and append my signature.
    16. 16. Some Code Hey WP! When you’reprocessing standard content, call this function!
    17. 17. Take the value WP provides us, add my signature, give it back.
    18. 18. It’s as easy as that.
    19. 19. But we cancomplicate things...
    20. 20. Archives, Listings, etc.Oops. I mean, I only want itto add my signature to the single post, not listings/ archives.
    21. 21. Archives, Listings, etc. What do you want to do now?Filter the content of all posts and append my signature
    22. 22. IF we’re on a single post page, THEN add my signature.
    23. 23. But we cancomplicate things...
    24. 24. Post Type ContentOops. I have a custom posttype called “Products,” andit’s adding my signature to those, too.
    25. 25. IF we’re on a single blog postpage, THEN add my signature.
    26. 26. Getting More Advanced
    27. 27. Using Objects Avoid tons of prefixed functionsUse a prefixed class to hold all your actions/filters
    28. 28. Using Objects
    29. 29. Do All Kinds of Fun Stuff
    30. 30. Plugins Do Way More Custom Post Types ShortcodesMetaboxes and metadata management
    31. 31. Plugins Do Way More Settings Pages Settings FieldsIncorporate Internationalization
    32. 32. Plugins Do Way More Redirect requests Modify Rewrite RulesEmulate CRON jobs (wp- cron.php)
    33. 33. Going Public
    34. 34. Get in the Repository Submit your plugin codehttp://wordpress.org/extend/plugins/ about/http://wordpress.org/extend/plugins/ about/faq/
    35. 35. Get in the Repository Readme.txthttp://wordpress.org/extend/plugins/ about/readme.txt
    36. 36. Get in the Repository Subversion access & management Support URL?Update within 2 years or hide
    37. 37. More Resources “Writing a Plugin”http://codex.wordpress.org/ Writing_a_Plugin“WordPress Coding Standards” http://codex.wordpress.org/ WordPress_Coding_Standards
    38. 38. Google Works Great
    39. 39. Keep It Simple Stupid.
    40. 40. Code is poetry.
    41. 41. Thanks.

    ×