wordpress plugin development practices

28
PLUGIN DEVELOPMENT PRACTICES 521 Dimensions TECHNOLGY SOLVING NEEDS Presented By: Dan Pastori @danpastori Sunday, June 3, 12

Upload: serversideup

Post on 05-Dec-2014

1.115 views

Category:

Technology


4 download

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

PLUGIN DEVELOPMENT PRACTICES

521 DimensionsTECHNOLGY SOLVING NEEDS

Presented By: Dan Pastori@danpastori

Sunday, June 3, 12

Page 2: Wordpress Plugin Development Practices

Dan Pastori

Sunday, June 3, 12

Page 3: Wordpress Plugin Development Practices

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

OTHER PRODUCTS I’VE DEVELOPED FOR

And of course custom applications!

Sunday, June 3, 12

Page 5: Wordpress Plugin Development Practices

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

PRE-REQUISITESUnderstanding of PHP

Motivation/Consistency

A goal to develop towards

Sunday, June 3, 12

Page 7: Wordpress Plugin Development Practices

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

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

BEGIN YOUR PLUGIN

Sunday, June 3, 12

Page 10: Wordpress Plugin Development Practices

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

ADD MAIN FILE/wp-content/plugins/[NAME]/[NAME].php

Sunday, June 3, 12

Page 12: Wordpress Plugin Development Practices

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

OOP VS FUNCTIONAL?

Modern programming practices say OOP

Both work!

Sunday, June 3, 12

Page 14: Wordpress Plugin Development Practices

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

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

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

WORKING WITH THE DATABASEglobal $wpdb object

dbDelta()

Sunday, June 3, 12

Page 18: Wordpress Plugin Development Practices

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

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

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

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

MEDIA GALLERYwp_insert_attachment($attachment, $filename,

$parentPostID)

Sunday, June 3, 12

Page 23: Wordpress Plugin Development Practices

PERMISSIONS

current_user_can('manage_options')

http://codex.wordpress.org/Roles_and_Capabilities

Sunday, June 3, 12

Page 24: Wordpress Plugin Development Practices

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

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

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

LAUNCH PLUGINHave your Mom use your plugin

Accept criticism

Maintain thorough documentation

Sunday, June 3, 12

Page 28: Wordpress Plugin Development Practices

QUESTIONS?

@danpastori

Sunday, June 3, 12