wordpress plugin development practices

Post on 05-Dec-2014

1.116 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

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

PLUGIN DEVELOPMENT PRACTICES

521 DimensionsTECHNOLGY SOLVING NEEDS

Presented By: Dan Pastori@danpastori

Sunday, June 3, 12

Dan Pastori

Sunday, June 3, 12

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

OTHER PRODUCTS I’VE DEVELOPED FOR

And of course custom applications!

Sunday, June 3, 12

WORDPRESS IS THE BEST!(at least from my experience!)

Great Community

Great Documentation

Fast learning curve

Sunday, June 3, 12

PRE-REQUISITESUnderstanding of PHP

Motivation/Consistency

A goal to develop towards

Sunday, June 3, 12

WORDPRESS TERMINOLOGY2 Types of Hooks:

1. Filter - Modifies text before it hits the screen.

2. Action - Hooks launched during execution.

Sunday, June 3, 12

WHERE TO BEGIN?

1. Find a need

4. Jump right in3. Prototype

2. Focus on that need

Sunday, June 3, 12

BEGIN YOUR PLUGIN

Sunday, June 3, 12

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

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

Sunday, June 3, 12

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

OOP VS FUNCTIONAL?

Modern programming practices say OOP

Both work!

Sunday, June 3, 12

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

register_activation_hook(__FILE__, ‘function_name’)

What happens when you activate and deactivate?

register_deactivation_hook(__FILE__, ‘function_name’)

Sunday, June 3, 12

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

WORKING WITH THE DATABASEglobal $wpdb object

dbDelta()

Sunday, June 3, 12

INITIAL INSTALL

1. Check for upgrades

If {installed version} != {plugin version}

2. Create Tables

3. Set options

Sunday, June 3, 12

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

DASHBOARD VISUAL APPEALOne management page, append to settings menu

Multiple management pages, have it’s own heading

Sunday, June 3, 12

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

MEDIA GALLERYwp_insert_attachment($attachment, $filename,

$parentPostID)

Sunday, June 3, 12

PERMISSIONS

current_user_can('manage_options')

http://codex.wordpress.org/Roles_and_Capabilities

Sunday, June 3, 12

SHORTCODES

extract( shortcode_atts( array( 'categoryID' => 'all',

), $attributes ));

add_shortcode('product-list', 'product_list_shortcode');

Sunday, June 3, 12

ENSURE PLUGIN QUALITYBe accepting of criticism

DOCUMENT... PLEASE :)

Update

Don’t solve everything, do one thing right

Sunday, June 3, 12

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

LAUNCH PLUGINHave your Mom use your plugin

Accept criticism

Maintain thorough documentation

Sunday, June 3, 12

QUESTIONS?

@danpastori

Sunday, June 3, 12

top related