Plugin Development Practices
Upcoming SlideShare
Loading in...5
×
 

Plugin Development Practices

on

  • 1,854 views

Presentation given at Wordcamp Chicago 2012 about developing Wordpress plugins.

Presentation given at Wordcamp Chicago 2012 about developing Wordpress plugins.

Statistics

Views

Total Views
1,854
Views on SlideShare
1,851
Embed Views
3

Actions

Likes
2
Downloads
19
Comments
0

1 Embed 3

https://twitter.com 3

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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 Plugin Development Practices Presentation Transcript

  • PLUGIN DEVELOPMENT PRACTICESPresented By: Dan Pastori @danpastori 521 Dimensions TECHNOLGY SOLVING NEEDS
  • Dan Pastori
  • WHO AM I?Primary PHP/Java DeveloperCo-Founded 521 DimensionsBeen tearing apart Wordpress for 3 yearsBuilt two large plugins and one theme
  • PRODUCTS I’VE DEVELOPED FOR And of course custom applications!
  • WORDPRESS IS THE BEST! (at least from my experience!)Great DocumentationGreat CommunityFast learning curve
  • PRE-REQUISITESUnderstanding of PHPMotivation/ConsistencyA goal to develop towards
  • BEGIN THE JOURNEY
  • COMMON WP TERMINOLOGYHooks (there are 2 types):1. A Filter - Modifies text before it hits the screen.2. An Action - Hooks launched during execution.
  • WHAT SHOULD I BUILD?1. Find a need2. Focus on the need3. Prototype4. Jump right in and start building!
  • 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
  • ADD MAIN FILE/wp-content/plugins/[NAME]/[NAME].php* File must be named the name of your plugin
  • 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*/
  • OOP VS PROCEDURAL?Modern programming practices say OOPBoth work!I recommend OOP if you are familiar
  • BEGIN CODING!DO NOT OVER-WRITE CORE FUNCTIONALITYInteracting with the Core: Predefined Functions Actions Filters(They’re there for a reason!)
  • 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));
  • 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’ );
  • __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
  • WORKING WITH THE DATABASEglobal $wpdb object $wpdb->query($query) $wpdb->get_results($query) $wpdb->print_error($query)dbDelta()
  • INITIAL INSTALL In your install() function1. Check for upgrades If {installed version} != {plugin version}2. Create Tables3. Set options
  • CSS AND JSRegister first, enqueue secondwp_register_script(product_js, plugins_url(/js/product_list.js,__FILE__));wp_enqueue_script(thickbox,null,array(jquery));
  • 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);
  • DASHBOARD VISUAL APPEALOne management page, append to settings menuMultiple management pages, have it’s own heading
  • PERMISSIONSPrevents unwanted accesscurrent_user_can(manage_options) http://codex.wordpress.org/Roles_and_Capabilities
  • 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]
  • ENSURE PLUGIN QUALITYNot only be accepting, but invite criticismDOCUMENT... PLEASE :)UpdateDon’t solve everything, do one thing right
  • 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!
  • LAUNCH PLUGINHave your Mom use your pluginAccept criticismMaintain thorough documentationWebsite maybe?
  • QUESTIONS? @