Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Writing Your First WordPress Plugin
1. Writing Your
First Plugin
by Mark Jaquith
@markjaquith
markjaquith.com
Saturday, August 21, 2010
2. Assumptions
• You know PHP syntax
• You’re targeting PHP 5
Saturday, August 21, 2010
3. What I want you to learn
• Plugins change what
WordPress does
• They rely on the concepts of
actions and filters
• There are numerous internal
WordPress APIs for you to use
Saturday, August 21, 2010
4. What is a Plugin?
• PHP code that sits in separate
files
• Integrates tightly with
WordPress
• Can add, alter, or remove
functionality
Saturday, August 21, 2010
5. Where?
• wp-content/plugins/name.php
• wp-content/plugins/folder/name.php
• WordPress only looks one level deep
• It looks for .php files with a plugin
header
Saturday, August 21, 2010
6. Plugin Header
“Plugin Name” is required.
Saturday, August 21, 2010
7. Basic Structure
• Build some stuff
• Tell WordPress to use that stuff
when WordPress does certain
stuff
Saturday, August 21, 2010
8. Actions
• Triggered when various things
happen in WordPress core
• “Wakes up” code you’ve
registered against that action
Saturday, August 21, 2010
20. Most Important
Action in WordPress
init
Saturday, August 21, 2010
21. Let’s build a plugin!
• Insert mailing address and phone number into a
post or a page
• Use a shortcode... [address]
• Configurable address and phone number
• Option to show phone number by default (or not)
• Ability to override the phone number default
Saturday, August 21, 2010