1. WordPress Plugin Development for Beginners
John P. Bloch
Senior Web Developer
Avendi Media, Inc.
http://www.johnpbloch.com/
@johnpbloch
2. What Are Plugins?
The stupid answer:
Anything you want*
*theoretically, at least
The useful answer:
Non-essential and elective aspects of any given
WordPress installation
3. Wait a Minute...
Aren't plugins just
extensions of
WordPress? Don't
they just add
functionality that isn't
there?
4. Plugins are Part of WordPress
Plugins have primacy of place
Plugins interact with WordPress in the same
way WordPress interacts with itself
6. How Do Plugins Work?
Almost all plugin use hooks. There are two
kinds of hooks:
Actions
Filters
What's the difference?
Filters expect you to return something, and...
… that's it!
Hooks let you tell WordPress to execute a
function when the specified hook fires
7. How To Use Hooks
Filters:
<?php add_filter( 'filter_name', 'function_name' ); ?>
Actions:
<?php add_action( 'action_name', 'func_name' ); ?>
Both functions take two optional arguments:
Priority
Accepted Arguments
8. How To Fire Hooks
To fire an action:
<?php do_action( 'action_name' ); ?>
This fires all functions hooked into that action
To fire a filter:
<?php apply_filters( 'filter_name', 'Filter value' ); ?>
The 'Filter value' will be the first argument of each
hooked function
apply_filters will return the filtered input
9. How Does Priority Work?
Actions and filters are
executed in the order
they are added. So
this code will echo:
First
Second
Third
10. How Does Priority Work?
Priority changes this
order. Actions and
filters have a default
priority of 10. Using a
lower number gives it
higher priority. This
code ouputs:
Third
First
Second
11. Accepted Arguments
Accepted arguments allows you to specify how
many arguments to send to a hooked function
Defaults to 1 for both actions and filters
The following would output:
Don't mention Joomla
Don't mention
13. But Wait! There's More!
One more way to hook into WordPress is
through shortcodes
Shortcodes are inserted into a post or page
from the editor; WordPress replaces the
shortcode tags with dynamically generated
content
Shortcodes are kind of like HTML:
[foo bar='bar']
[foo bar='bar']Some Content[/foo]
14. How to Add a Shortcode
Shortcodes must be registered:
<?php add_shortcode( 'tag_name', 'function_name' ); ?>
Shortcode handlers take two optional
arguments:
Arguments: an array of arguments from the
shortcode
Content: the content (if any) of the shortcode
Shortcode handlers should return, not echo,
their content
19. Adding Your Plugin to the Directory
http://wordpress.org/extend/plugins/add/
Answer a few questions
Name – Very important! This will determine the
name of the directory your plugin creates
Description
Plugin URL (optional)
… And wait!
20. What is SVN?
SVN, or Subversion, is a version control program.
Others include Git and Mercurial. Subversion is
used for core WordPress development/distribution
and official plugin development/distribution.
Once you have your repository, anybody in the
world can check it out. Only you* can check files
into it.
*Technically, Nacin and some others have global plugin repo commit
access. #blamenacin
21. How to Use SVN
If you are on windows and use TortoiseSVN,
just follow these next steps substituting ”Click X
menu item” for ”Execute X command”
Go to the directory into which you'd like the
repo to go:
~$ cd Documents/svn
Check out your repository for the first time:
~$ svn co http://plugins.svn.wordpress.org/custom-post-permalinks/ custom-post-permalinks
Edit to your heart's content
22. How to Use SVN
When you're done making changes (or reach a
good stopping point), commit your changes:
~$ svn ci -m 'This is a description of the commit!'
… Tada!
23. Some Other Notes on SVN
Updating your plugin
Tagging vs. Stable Trunk
Branching
Adding committers (and other admin tools)
24. Further Reading
Core.
Core.
Core.
Seriously. Just read core's runtime execution.
Line by line.
25. Now Let's Get Down to Business!
Time to switch gears, open VIM,
and write a plugin!