Wordpress Plugin Development Practices

1,026
-1

Published on

These slides are from a presentation given by Dan Pastori of 521 Dimensions that were presented at Milwaukee Wordcamp in June of 2012. These slides represent the best practices when it comes to developing a Wordpress Plugin.

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

  • Be the first to like this

No Downloads
Views
Total Views
1,026
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Wordpress Plugin Development Practices

  1. 1. PLUGIN DEVELOPMENT PRACTICES Presented By: Dan Pastori @danpastori 521 Dimensions TECHNOLGY SOLVING NEEDSSunday, June 3, 12
  2. 2. Dan PastoriSunday, June 3, 12
  3. 3. WHO IS DAN PASTORI? Primary PHP/Java Developer Co-Founded 521 Dimensions Built two large plugins and one theme Been tearing apart Wordpress for 3 yearsSunday, June 3, 12
  4. 4. OTHER PRODUCTS I’VE DEVELOPED FOR And of course custom applications!Sunday, June 3, 12
  5. 5. WORDPRESS IS THE BEST! (at least from my experience!) Great Documentation Great Community Fast learning curveSunday, June 3, 12
  6. 6. PRE-REQUISITES Understanding of PHP Motivation/Consistency A goal to develop towardsSunday, June 3, 12
  7. 7. WORDPRESS TERMINOLOGY 2 Types of Hooks: 1. Filter - Modifies text before it hits the screen. 2. Action - Hooks launched during execution.Sunday, June 3, 12
  8. 8. WHERE TO BEGIN? 1. Find a need 2. Focus on that need 3. Prototype 4. Jump right inSunday, June 3, 12
  9. 9. BEGIN YOUR PLUGINSunday, June 3, 12
  10. 10. STRUCTURING PLUGIN Create Directories /wp-content/plugins/[NAME] /wp-content/plugins/[NAME]/css /wp-content/plugins/[NAME]/js /wp-content/plugins/[NAME]/images /wp-content/plugins/[NAME]/includesSunday, June 3, 12
  11. 11. ADD MAIN FILE /wp-content/plugins/[NAME]/[NAME].phpSunday, June 3, 12
  12. 12. Add Header In Main File /* Plugin Name: [NAME] Plugin URI: http://www.521dimensions.com/wp-pictures Description: Pictures in Wordpress! Version: 1.0 Author: Dan Pastori Author URI: http://www.521dimensions.com License: GPL2 */Sunday, June 3, 12
  13. 13. OOP VS FUNCTIONAL? Modern programming practices say OOP Both work!Sunday, June 3, 12
  14. 14. BEGIN CODING! DO NOT OVER-WRITE CORE FUNCTIONALITY Use predefined functions as much as possible (They’re there for a reason!)Sunday, June 3, 12
  15. 15. What happens when you activate and deactivate? register_activation_hook(__FILE__, ‘function_name’) register_deactivation_hook(__FILE__, ‘function_name’)Sunday, June 3, 12
  16. 16. Open [NAME].php OOP ... class WPPictures { static function install() { // do not generate any output here } } register_activation_hook( __FILE__, array(WPPictures, install) ); Functional ... function wp_pictures_install(){ } register_activation_hook( __FILE__, ‘wp_pictures_install’ );Sunday, June 3, 12
  17. 17. WORKING WITH THE DATABASE global $wpdb object dbDelta()Sunday, June 3, 12
  18. 18. INITIAL INSTALL 1. Check for upgrades If {installed version} != {plugin version} 2. Create Tables 3. Set optionsSunday, June 3, 12
  19. 19. CSS AND JS Register first, enqueue second wp_register_script(product_js, plugins_url(/js/ product_list.js, __FILE__)); wp_enqueue_script(thickbox,null,array(jquery));Sunday, June 3, 12
  20. 20. DASHBOARD VISUAL APPEAL One management page, append to settings menu Multiple management pages, have it’s own headingSunday, June 3, 12
  21. 21. ADMIN MENUS add_menu_page(PAGE TITLE, MENU TITLE, PERMISSION, SLUG, FUNCTION, LOGO); add_submenu_page(PARENT SLUG, PAGE TITLE, MENU TITLE, CAPABILITY, MENU SLUG,FUNCTION);Sunday, June 3, 12
  22. 22. MEDIA GALLERY wp_insert_attachment($attachment, $filename, $parentPostID)Sunday, June 3, 12
  23. 23. PERMISSIONS current_user_can(manage_options) http://codex.wordpress.org/Roles_and_CapabilitiesSunday, June 3, 12
  24. 24. SHORTCODES add_shortcode(product-list, product_list_shortcode); extract( shortcode_atts( array( categoryID => all, ), $attributes ));Sunday, June 3, 12
  25. 25. ENSURE PLUGIN QUALITY Be accepting of criticism DOCUMENT... PLEASE :) Update Don’t solve everything, do one thing rightSunday, June 3, 12
  26. 26. BE THE SERVER ADMIN’S FRIEND (And have a quality plugin) Minimize requests Make sure your resources are present Use common php packages Don’t require 777 on ANY directory!Sunday, June 3, 12
  27. 27. LAUNCH PLUGIN Have your Mom use your plugin Accept criticism Maintain thorough documentationSunday, June 3, 12
  28. 28. QUESTIONS? @danpastoriSunday, June 3, 12
  1. A particular slide catching your eye?

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

×