wordpress plugin development for beginners
TRANSCRIPT
WordPress Plugin Development for Beginners
John P. BlochSenior Web DeveloperAvendi Media, Inc.http://www.johnpbloch.com/@johnpbloch
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
Wait a Minute...
Aren't plugins just extensions of WordPress? Don't they just add functionality that isn't there?
Plugins are Part of WordPress
Plugins have primacy of place
Plugins interact with WordPress in the same way WordPress interacts with itself
An Example Plugin
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
How To Use Hooks
Filters:
Actions:
Both functions take two optional arguments:Priority
Accepted Arguments
How To Fire Hooks
To fire an action:
This fires all functions hooked into that action
To fire a filter:
The 'Filter value' will be the first argument of each hooked function
apply_filters will return the filtered input
How Does Priority Work?
Actions and filters are executed in the order they are added. So
this code will echo:
First
Second
Third
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
Accepted Arguments
Accepted arguments allows you to specify how many arguments to send to a hooked functionDefaults to 1 for both actions and filters
The following would output:
Don't mention Joomla
Don't mention
Some Common Hooks
Actionsinit
template_redirect
admin_init
after_setup_theme
wp_loaded
wp_head
wp_footer
admin_menu
Filtersthe_content
the_title
wp_title
template_include
body_class
post_class
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]
How to Add a Shortcode
Shortcodes must be registered:
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
An Example of a Shortcode
Developer Toolbox
Local development environmentLAMPP Stack (XAMPP http://apachefriends.org)
SubversionWindows: TortoiseSVN or Cygwin
Everything else: CLI
Text Editor
FTP clientMac: Transmit
SSH ClientWindows: Putty
ReferencePHPXref (http://www.phpxref.com)
WordPress Developer Toolbox
Official Support ChannelsWordPress Codex (http://codex.wordpress.org/)
WordPress Forums (http://wordpress.org/support/)
IRC Channel #wordpress (chat.freenode.net)
Mailing Lists (sort of) (http://codex.wordpress.org/Mailing_Lists)
Unofficial Support ChannelsWordPress Answers (http://wordpress.stackexchange.com/)
WordPress Docs (http://wpdocs.labs.thedextrousweb.com/)
Alot of Books
Just Because
Adding Your Plugin to the Directory
http://wordpress.org/extend/plugins/add/
Answer a few questionsName Very important! This will determine the name of the directory your plugin creates
Description
Plugin URL (optional)
And wait!
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
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
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!
Some Other Notes on SVN
Updating your plugin
Tagging vs. Stable Trunk
Branching
Adding committers (and other admin tools)
Further Reading
Core.
Core.
Core.
Seriously. Just read core's runtime execution.
Line by line.
Now Let's Get Down to Business!
Time to switch gears, open VIM,and write a plugin!
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso