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.
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 years
Sunday, June 3, 12
4. OTHER PRODUCTS I’VE DEVELOPED FOR
And of course custom applications!
Sunday, June 3, 12
5. WORDPRESS IS THE BEST!
(at least from my experience!)
Great Documentation
Great Community
Fast learning curve
Sunday, June 3, 12
6. PRE-REQUISITES
Understanding of PHP
Motivation/Consistency
A goal to develop towards
Sunday, June 3, 12
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. WHERE TO BEGIN?
1. Find a need
2. Focus on that need
3. Prototype
4. Jump right in
Sunday, June 3, 12
11. ADD MAIN FILE
/wp-content/plugins/[NAME]/[NAME].php
Sunday, June 3, 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. OOP VS FUNCTIONAL?
Modern programming practices say OOP
Both work!
Sunday, June 3, 12
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. What happens when you activate and
deactivate?
register_activation_hook(__FILE__, ‘function_name’)
register_deactivation_hook(__FILE__, ‘function_name’)
Sunday, June 3, 12
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. WORKING WITH THE DATABASE
global $wpdb object
dbDelta()
Sunday, June 3, 12
18. INITIAL INSTALL
1. Check for upgrades
If {installed version} != {plugin version}
2. Create Tables
3. Set options
Sunday, June 3, 12
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. DASHBOARD VISUAL APPEAL
One management page, append to settings menu
Multiple management pages, have it’s own heading
Sunday, June 3, 12
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. MEDIA GALLERY
wp_insert_attachment($attachment, $filename,
$parentPostID)
Sunday, June 3, 12
23. PERMISSIONS
current_user_can('manage_options')
http://codex.wordpress.org/Roles_and_Capabilities
Sunday, June 3, 12
25. ENSURE PLUGIN QUALITY
Be accepting of criticism
DOCUMENT... PLEASE :)
Update
Don’t solve everything, do one thing right
Sunday, June 3, 12
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. LAUNCH PLUGIN
Have your Mom use your plugin
Accept criticism
Maintain thorough documentation
Sunday, June 3, 12