wordpress plugin development practices
DESCRIPTION
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.TRANSCRIPT
![Page 1: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/1.jpg)
PLUGIN DEVELOPMENT PRACTICES
521 DimensionsTECHNOLGY SOLVING NEEDS
Presented By: Dan Pastori@danpastori
Sunday, June 3, 12
![Page 2: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/2.jpg)
Dan Pastori
Sunday, June 3, 12
![Page 3: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/3.jpg)
WHO IS DAN PASTORI?
Primary PHP/Java Developer
Co-Founded 521 Dimensions
Been tearing apart Wordpress for 3 years
Built two large plugins and one theme
Sunday, June 3, 12
![Page 4: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/4.jpg)
OTHER PRODUCTS I’VE DEVELOPED FOR
And of course custom applications!
Sunday, June 3, 12
![Page 5: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/5.jpg)
WORDPRESS IS THE BEST!(at least from my experience!)
Great Community
Great Documentation
Fast learning curve
Sunday, June 3, 12
![Page 6: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/6.jpg)
PRE-REQUISITESUnderstanding of PHP
Motivation/Consistency
A goal to develop towards
Sunday, June 3, 12
![Page 7: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/7.jpg)
WORDPRESS TERMINOLOGY2 Types of Hooks:
1. Filter - Modifies text before it hits the screen.
2. Action - Hooks launched during execution.
Sunday, June 3, 12
![Page 8: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/8.jpg)
WHERE TO BEGIN?
1. Find a need
4. Jump right in3. Prototype
2. Focus on that need
Sunday, June 3, 12
![Page 9: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/9.jpg)
BEGIN YOUR PLUGIN
Sunday, June 3, 12
![Page 10: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/10.jpg)
STRUCTURING PLUGIN
/wp-content/plugins/[NAME]
Create Directories
/wp-content/plugins/[NAME]/css
/wp-content/plugins/[NAME]/js
/wp-content/plugins/[NAME]/images
/wp-content/plugins/[NAME]/includes
Sunday, June 3, 12
![Page 11: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/11.jpg)
ADD MAIN FILE/wp-content/plugins/[NAME]/[NAME].php
Sunday, June 3, 12
![Page 12: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/12.jpg)
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*/
Sunday, June 3, 12
![Page 13: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/13.jpg)
OOP VS FUNCTIONAL?
Modern programming practices say OOP
Both work!
Sunday, June 3, 12
![Page 14: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/14.jpg)
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
![Page 15: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/15.jpg)
register_activation_hook(__FILE__, ‘function_name’)
What happens when you activate and deactivate?
register_deactivation_hook(__FILE__, ‘function_name’)
Sunday, June 3, 12
![Page 16: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/16.jpg)
Open [NAME].php
...class WPPictures { static function install() { // do not generate any output here }}register_activation_hook( __FILE__, array('WPPictures', 'install') );
OOP
Functional
...function wp_pictures_install(){
}register_activation_hook( __FILE__, ‘wp_pictures_install’ );
Sunday, June 3, 12
![Page 17: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/17.jpg)
WORKING WITH THE DATABASEglobal $wpdb object
dbDelta()
Sunday, June 3, 12
![Page 18: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/18.jpg)
INITIAL INSTALL
1. Check for upgrades
If {installed version} != {plugin version}
2. Create Tables
3. Set options
Sunday, June 3, 12
![Page 19: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/19.jpg)
CSS AND JSRegister first, enqueue second
wp_enqueue_script('thickbox',null,array('jquery'));
wp_register_script('product_js', plugins_url('/js/product_list.js', __FILE__));
Sunday, June 3, 12
![Page 20: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/20.jpg)
DASHBOARD VISUAL APPEALOne management page, append to settings menu
Multiple management pages, have it’s own heading
Sunday, June 3, 12
![Page 21: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/21.jpg)
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
![Page 22: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/22.jpg)
MEDIA GALLERYwp_insert_attachment($attachment, $filename,
$parentPostID)
Sunday, June 3, 12
![Page 23: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/23.jpg)
PERMISSIONS
current_user_can('manage_options')
http://codex.wordpress.org/Roles_and_Capabilities
Sunday, June 3, 12
![Page 24: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/24.jpg)
SHORTCODES
extract( shortcode_atts( array( 'categoryID' => 'all',
), $attributes ));
add_shortcode('product-list', 'product_list_shortcode');
Sunday, June 3, 12
![Page 25: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/25.jpg)
ENSURE PLUGIN QUALITYBe accepting of criticism
DOCUMENT... PLEASE :)
Update
Don’t solve everything, do one thing right
Sunday, June 3, 12
![Page 26: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/26.jpg)
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
![Page 27: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/27.jpg)
LAUNCH PLUGINHave your Mom use your plugin
Accept criticism
Maintain thorough documentation
Sunday, June 3, 12
![Page 28: Wordpress Plugin Development Practices](https://reader033.vdocument.in/reader033/viewer/2022061206/54829ca7b4af9f910d8b47e1/html5/thumbnails/28.jpg)
QUESTIONS?
@danpastori
Sunday, June 3, 12