In this chapter, you discover how to use a plugin template to deal with some of the programming you will use repeatedly as a plugin developer. You must also include some basic information within your plugin so that the users of your plugin identify the plugin easily. Standard practices also exist for the elements that should be included in your plugin if you intend to submit it to the official WordPress Plugin Directory at http://wordpress.org/extend/plugins. Plugins submitted to the directory are reviewed and vetted by WordPress developers to make sure that your plugin has all the necessary elements, is formatted correctly, and meets the standards of practice for all plugins.
Among these necessary elements — the basics — is a short snippet of code at the top of your plugin file that identifies seven important identifying characteristics of your plugin:
For example, say you're writing a plugin that allows people to connect their blog to the Twitter service. Would naming your plugin My Great Plugin make sense? On the other hand, is giving the plugin a name like WordPress Twitter Connect more helpful? The first name may go far to serve your ego but is utterly useless from a user's standpoint. Create plugin titles that make sense to the user and make the function of the plugin easily identifiable.
If you intend to submit your plugin to the WordPress Plugin Directory, the words you use in the description and title will identify your plugin in search results there. Therefore, when writing the description of your plugin, use terms that will help users find your plugin easily. When people search for a particular term in the directory, all the plugins with that term in either the title or description will appear.
Figure 6-1 displays the WordPress Plugin Directory search results page for the term Twitter; the titles and descriptions all contain Twitter and help identify the plugin in the search results.
In Book I, Chapter 3, we discuss the WordPress development and release cycle as it pertains to the WordPress software. Within that chapter, you find information about the various versions of WordPress, how and why different version numbers exist, and point releases versus major releases.
The version numbers are up to you, of course; this is simply a standard practice by many developers who release software in order to keep their versions organized.
The necessary code to include these seven items looks like this:
<?php /* Plugin Name: Your Plugin Name Plugin URI: Web Address of your Plugin Description: A brief description of the Plugin. Version: Version Number Author: Name(s) of the plugin Author(s) Author URI: Web Address of the plugin author(s) Web site License: License name (ie: GPL2) */ ?>
It is customary to include a licensing statement in the header of your plugin that indicates adherence to the GPLv2 license. This statement is easy to include and formatted like this:
<?php /* Copyright 2011 WordPress Twitter Connect Lisa Sabin-Wilson This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ?>
Figure 6-2 shows the Plugins page, displaying plugin names and descriptions.