Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 7 • Making the Most of WordPress Plugins 181


Naturally, you’d want to change YEAR, PLUGIN_AUTHOR_NAME, and PLUGIN AUTHOR
E-MAIL to the correct information. You can also include the full license as a text file, aptly
named license.txt of course. You can obtain the license from http://www.gnu.org/copyleft/
gpl.html.


That’s about it. All you need for WordPress to find the plugin is one single file with an identify-
ing header. Dropping it in wp-content/plugins/ will result in its being listed in the Plugins
section of WordPress. Activate it from the Plugins admin page, and it will be available to you
in your theme and from WordPress’s actions themselves.


This is where the fun part begins because now you have to figure out what you need to do and
how you’ll accomplish it.


Whether you’re planning on writing the plugin you think will change the way you use Word-
Press or just need some extra functionality for your latest project, you should go through the
following plugin checklist before getting started. It may just save you some time and
headaches.


◾ Is there a plugin for this already? If there is, consider using that instead or forking/editing
it if it nearly does what you want.
◾ Make sure that you’ve got a unique name for your plugin. Don’t just check the WordPress.
org plugin directory; Google it to make sure. One way to ensure a unique name is to add
your company’s initials to the front of the plugin name, such as acme_pluginname.
◾ Decide on a unique prefix to all your functions and stick to it. That way, you’re doing
your part in eliminating any unnecessary conflicts due to a similar naming structure. This
is important: Prefix everything!
◾ Do you want to internationalize your plugin? You really should; it works the same way as
with themes and is pretty easy after all.
◾ Should this plugin have widget support? If it should, what kind of settings should it have?
◾ Do you need a Settings page within the admin interface? Try to keep settings to a
minimum as they tend to confuse users.
◾ What license should the plugin have? Keep in mind that it has to be GPL-compatible to
get hosted by the WordPress.org directory.
◾ Don’t forget a final check: Is the header up to date? Is the version number correct? Do all
the links work? Is every necessary file in the package? And last but not least, have you
spell-checked your plugin?

METHODS FOR INCORPORATING YOUR PLUGINS


Writing plugins is more like traditional PHP coding than working with WordPress themes.
Although you may use both template and conditional tags, most likely, you’ll be writing a lot
on your own as well, not relying so much on the built-in features that WordPress tags offer
you. Of course, it all depends on what your plugin does, but overall plugin development is
more you than WordPress.

Free download pdf