Plugin Development Practices

2,138 views

Published on

Presentation given at Wordcamp Chicago 2012 about developing Wordpress plugins.

Published in: Technology, Art & Photos
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,138
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
23
Comments
0
Likes
3
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
  • Plugin Development Practices

    1. PLUGIN DEVELOPMENT PRACTICESPresented By: Dan Pastori @danpastori 521 Dimensions TECHNOLGY SOLVING NEEDS
    2. Dan Pastori
    3. WHO AM I?Primary PHP/Java DeveloperCo-Founded 521 DimensionsBeen tearing apart Wordpress for 3 yearsBuilt two large plugins and one theme
    4. PRODUCTS I’VE DEVELOPED FOR And of course custom applications!
    5. WORDPRESS IS THE BEST! (at least from my experience!)Great DocumentationGreat CommunityFast learning curve
    6. PRE-REQUISITESUnderstanding of PHPMotivation/ConsistencyA goal to develop towards
    7. BEGIN THE JOURNEY
    8. COMMON WP TERMINOLOGYHooks (there are 2 types):1. A Filter - Modifies text before it hits the screen.2. An Action - Hooks launched during execution.
    9. WHAT SHOULD I BUILD?1. Find a need2. Focus on the need3. Prototype4. Jump right in and start building!
    10. STRUCTURE YOUR PLUGINCreate Directories/wp-content/plugins/[NAME] /wp-content/plugins/[NAME]/css /wp-content/plugins/[NAME]/js /wp-content/plugins/[NAME]/imagesDepending on Coding Style /wp-content/plugins/[NAME]/classes /wp-content/plugins/[NAME]/includes
    11. ADD MAIN FILE/wp-content/plugins/[NAME]/[NAME].php* File must be named the name of your plugin
    12. Now for some excitement! Add Header in Main File/*Plugin Name: [NAME]Plugin URI: http://www.521dimensions.com/wp-picturesDescription: Pictures in Wordpress!Version: 1.0Author: Dan PastoriAuthor URI: http://www.521dimensions.comLicense: GPL2*/
    13. OOP VS PROCEDURAL?Modern programming practices say OOPBoth work!I recommend OOP if you are familiar
    14. BEGIN CODING!DO NOT OVER-WRITE CORE FUNCTIONALITYInteracting with the Core: Predefined Functions Actions Filters(They’re there for a reason!)
    15. What happens when you activate and deactivate? Proceduralregister_activation_hook(__FILE__, ‘function_name’)register_deactivation_hook(__FILE__, ‘function_name’) OOPregister_activation_hook(__FILE__, array($this, product_list_install));register_deactivation_hook(__FILE__, array($this, product_list_deactivate));
    16. Open [NAME].phpOOP...class WPPictures { static function install() { // do not generate any output here }}register_activation_hook( __FILE__, array(WPPictures, install) );Procedural...function wp_pictures_install(){}register_activation_hook( __FILE__, ‘wp_pictures_install’ );
    17. __FILE__ (IT’S MAGIC!)It’s a pre-defined constant in PHPThe full path and filename of the file. If used inside an include,the name of the included file is returned.http://php.net/manual/en/language.constants.predefined.php
    18. WORKING WITH THE DATABASEglobal $wpdb object $wpdb->query($query) $wpdb->get_results($query) $wpdb->print_error($query)dbDelta()
    19. INITIAL INSTALL In your install() function1. Check for upgrades If {installed version} != {plugin version}2. Create Tables3. Set options
    20. CSS AND JSRegister first, enqueue secondwp_register_script(product_js, plugins_url(/js/product_list.js,__FILE__));wp_enqueue_script(thickbox,null,array(jquery));
    21. ADMIN MENUSadd_menu_page(PAGE TITLE, MENU TITLE, PERMISSION, SLUG, FUNCTION, LOGO);add_submenu_page(PARENT SLUG, PAGE TITLE, MENU TITLE, CAPABILITY, MENU SLUG, FUNCTION);
    22. DASHBOARD VISUAL APPEALOne management page, append to settings menuMultiple management pages, have it’s own heading
    23. PERMISSIONSPrevents unwanted accesscurrent_user_can(manage_options) http://codex.wordpress.org/Roles_and_Capabilities
    24. SHORTCODESDramatically increases user-experience of your pluginAllows for custom control of display of dataadd_shortcode(product-list, product_list_shortcode);extract( shortcode_atts( array( categoryID => all, ), $attributes ));[product-list category-id = 1]
    25. ENSURE PLUGIN QUALITYNot only be accepting, but invite criticismDOCUMENT... PLEASE :)UpdateDon’t solve everything, do one thing right
    26. BE THE SERVER ADMIN’S FRIEND (And have a quality plugin)Minimize requestsMake sure your resources are presentUse common php packagesDon’t require 777 on ANY directory!
    27. LAUNCH PLUGINHave your Mom use your pluginAccept criticismMaintain thorough documentationWebsite maybe?
    28. QUESTIONS? @

    ×