This document provides an overview of plugin development practices for WordPress. It discusses prerequisites for plugin development including understanding PHP and having a goal in mind. It covers common WordPress terminology, structuring a plugin with directories, adding the main plugin file, using object-oriented or procedural programming, interacting with the WordPress core, working with databases, adding CSS and JavaScript, creating admin menus, using permissions, implementing shortcodes, ensuring quality, and launching the plugin. The document aims to guide developers through best practices for building WordPress plugins.
8. COMMON WP TERMINOLOGY
Hooks (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 need
2. Focus on the need
3. Prototype
4. Jump right in and start building!
10. STRUCTURE YOUR PLUGIN
Create Directories
/wp-content/plugins/[NAME]
/wp-content/plugins/[NAME]/css
/wp-content/plugins/[NAME]/js
/wp-content/plugins/[NAME]/images
Depending on Coding Style
/wp-content/plugins/[NAME]/classes
/wp-content/plugins/[NAME]/includes
12. Now for some excitement!
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
*/
13.
14. OOP VS PROCEDURAL?
Modern programming practices say OOP
Both work!
I recommend OOP if you are familiar
15. BEGIN CODING!
DO NOT OVER-WRITE CORE FUNCTIONALITY
Interacting with the Core:
Predefined Functions
Actions
Filters
(They’re there for a reason!)
16. What happens when you activate and
deactivate?
Procedural
register_activation_hook(__FILE__, ‘function_name’)
register_deactivation_hook(__FILE__, ‘function_name’)
OOP
register_activation_hook(__FILE__, array($this, 'product_list_install'));
register_deactivation_hook(__FILE__, array($this, 'product_list_deactivate'));
17. Open [NAME].php
OOP
...
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’ );
18. __FILE__
(IT’S MAGIC!)
It’s a pre-defined constant in PHP
The 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
19. WORKING WITH THE DATABASE
global $wpdb object
$wpdb->query($query)
$wpdb->get_results($query)
$wpdb->print_error($query)
dbDelta()
20. INITIAL INSTALL
In your install() function
1. Check for upgrades
If {installed version} != {plugin version}
2. Create Tables
3. Set options
21. 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'));
25. SHORTCODES
Dramatically increases user-experience of your plugin
Allows for custom control of display of data
add_shortcode('product-list', 'product_list_shortcode');
extract( shortcode_atts( array(
'categoryID' => 'all',
), $attributes ));
[product-list category-id = 1]
26. ENSURE PLUGIN QUALITY
Not only be accepting, but invite criticism
DOCUMENT... PLEASE :)
Update
Don’t solve everything, do one thing right
27. 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!
28. LAUNCH PLUGIN
Have your Mom use your plugin
Accept criticism
Maintain thorough documentation
Website maybe?