plugin development - wordpress.com• wordpress developer since 2007 • initially built sites for a...

56
Plugin Development - Joey Kudish http://slides.jkudish.com

Upload: others

Post on 06-Mar-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Plugin Development

- Joey Kudish

http://slides.jkudish.com

Page 2: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

About me

• WordPress developer since 2007

• Initially built sites for a variety of clients + plugin

development

• Code Wrangler at WordPress.com / Automattic

since May 2012

• Originally from Montreal, moved to Vancouver

in 2011

Page 3: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 4: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

What’s a plugin?

Page 5: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

A plugin extends or modi!es WordPress to do something it

didn’t previously do

Page 6: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Themes can act as plugins. Oh and there’s

mu-plugins too.

Page 7: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Plugins can be huge...

Page 8: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

... or tiny.

Page 9: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

What’s in a plugin?

Page 10: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Where does it go?

wp-content/plugins/[plugin_name]or wp-content/mu-plugins/

Page 11: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

In order to “hook” into WordPress, we use action and !lter

hooks

Page 12: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Action hooks allow you to add your own code to WordPress’

call stack

Page 13: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Filter hooks allow you to modify an

existing variable or piece of information

Page 14: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Demo time

Page 15: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Let’s add Google Webmaster Tools

veri!cation to our site

Page 16: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 17: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 18: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 19: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 20: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Finding hooks• The best way is to get to know/search core (use

an IDE or a command line tool like ack)

• WordPress.org Codex (http://

codex.wordpress.org/)

• http://adambrown.info/p/wp_hooks

• Debug Bar + Debug Bar Action Hooks plugin

(http://wordpress.org/extend/plugins/debug-bar-

action-hooks/)

Page 21: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Some pro tips

Page 22: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Use built-in APIs, don’t re-invent the

wheel

Page 23: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Use WordPress coding standards

Page 24: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Be nice to other devs. and to your users Namespace your

classes and functions. Leave hooks for others.

Page 25: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Demo time

Page 26: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 27: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 28: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 29: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

hey that’s the !le we want to hook into

Page 30: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 31: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 32: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Let’s create our plugin

Page 33: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 34: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 35: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 36: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 37: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 38: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 39: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

It works, let’s look at the

!nished plugin

Page 40: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 41: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

A few words on Security

Page 42: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Don’t trust users

Page 43: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Sanitize input; escape output

http://codex.wordpress.org/Data_Validation

Page 44: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Protect users from malicious attacks;

use nonces to validate user actions

http://codex.wordpress.org/WordPress_Nonces

Page 45: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Use the built-in APIs and functions unless you

absolutely can’t. Keep re-usability in mind and avoid custom tables if possible.

Page 46: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Plugin Distribution

Page 47: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 48: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 49: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 50: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Further reading

Page 51: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 52: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 53: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic
Page 54: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Keep up with the Community

WordCamps/MeetupsWordPress.tv

WP DAILYWP TAVENWP REALMTWITTER

etc.

Page 56: Plugin Development - WordPress.com• WordPress developer since 2007 • Initially built sites for a variety of clients + plugin development • Code Wrangler at WordPress.com / Automattic

Thanks Winnipeg!

Q&Ahttp://slides.jkudish.com