1. How to create a
WordPress plugin.
WordCamp Toronto Dev 2012
@thisismyurl
2. What is a Plugin?
A WordPress plugin is a PHP based addition to the
WordPress blogging platform.
• Plugins are functions which interact with WordPress Core code;
• A Plugin changes what WordPress does;
• Plugins are stored external of the theme;
3. What can they do?
Since Plugins are executed as part of the WordPress platform,
they’re almost limitless.
• Plugins can interact with WordPress via Hooks and Actions;
• They can create, or interact with API’s in the WordPress system;
• Plugins can affect Posts, Pages, Users, or any part of the WordPress tool;
4. When should you use a
Plugin?
Plugin functions can be stored as a plugin, or in a theme
function.php file, why choose?
• Functions are specifically part of the theme;
• Plugins allow you to share code outside a theme, across multiple designs;
• Plugins can be activated in multisite environments;
5. Theme functions are
restricted to a single
theme.
Plugins deliver the same code to multiple blogs, on the same server
or across multiple hosting accounts.
6. How WordPress finds a
Plugin
WordPress will automatically locate plugins on a standard
install, adding them to the admin
• /wp-content/plugins/filename.php
• /wp-content/plugins/folder-name/filename.php
• WordPress will search one level deep in the plugins folder;
• Searches for .php files with a valid plugin header;
10. Play nice with other
functions
Remember WordPress shares your plugin functions across the
entire site, be unique
• Your plugins should use a unique name for all functions;
• function demo_plugin_function_name() for example;
• Plugin file load order is determined by WordPress;
11. What are Actions?
Actions are triggered by WordPress, causing your plugin to
spring to life.
• There’s an action for almost everything WordPress does
• http://codex.wordpress.org/Plugin_API/Action_Reference
12. What are Filters?
Filters allow you to change content WordPress
has created.
• There’s an filter for almost everything WordPress does
• http://codex.wordpress.org/Plugin_API
29. Be unique.
Remember Plugins interact will all the code on your
WordPress website, make sure you’re unique.
• Classes and Functions should use unique names;
• thisismyurl_plugin_name_function_name() for example;
30. Be descriptive.
Your Plugin is part of something else, make sure people can
easily understand your code.
• Elements should use verbose naming conventions, easy to understand;
• $i is bad;
• $loop_resume_posts is good;
31. Be consistent.
There are standards in the WordPress community, following
them makes it easy.
• The WordPress coding standards make coding easier in the long run;
• If you’re following your own coding standards, stick to them;
• http://codex.wordpress.org/WordPress_Coding_Standards
32. Be lazy, but smart.
In my experience, somebody else has already done a lot of the
heavy lifting so look before you code.
35. Fork it.
All plugins on WordPress.org are released under the GNU
licensing terms, if you can’t collaborate, innovate.
36. Give Back.
If you’ve written a WordPress Plugin that you think the
community will benefit from, submit it to WordPress.org for
review and consideration.