WordPress Plugin Development: Beginner's Guide
By Vladimir Prelovac
Packt Publishing, February 2009
WordPress is primarily known as a blogging tool, but many of its
fans argue that it is also a better content management system than many
another content management system.
Blogging is such a powerful approach to keeping websites fresh and
current that putting blogging capabilities at the center of a CMS is
arguably a better approach than grafting a blog onto the side of a more
general purpose CMS. WordPress can be used to add standing pages, not just
blog entries, so it's easy enough to add the standard "About Us" and "Contact
Us" material, or to have a branded home page people see before going to the blog. By extending the system, you can further to add your own custom application user interfaces and have them appear within the WordPress template.
One of the things that makes WordPress into a broader platform is
the Application Programming Interface it offers for plug-in
development, which is the topic of Vladimir Prelovac's book. The number
of existing plug-ins for WordPress is impressive, but knowing how to
construct your own frees is essential if you have unique requirements
or want to integrate existing code and applications. The APIs are
thoroughly documented on the WordPress website, but there is so much
information there that it's hard to know where to start.
The book makes it all more comprehensible by walking you through six
specific examples. It helps that the plug-ins you create in the process
are actually useful ones. For example, the one he calls Insights is a
blogger's utility for searching through past blog postings that the
author might want to link to or otherwise reference. The same tool will let you add photos retrieved from Flickr. This demonstrates
how to add functionality to the website administration screens.
Another example plug-in, Fancy Archives, shows how to customize the display of archives
pages with a script that checks for any images that may have been
included with a post so that they can be displayed as part of the
summary excerpt.
The WordPress API is based on a series of hooks -- filter hooks and
action hooks -- that your plugin can register an interest in. A filter
hook is used to process content retrieved from the database before it
is displayed on screen, or, conversely, to process content posted by
the user before it goes into the database. So this is where you can
insert special formatting or data cleanup steps. WordPress hands the
content to your function and expects you to return the modified version
of it. An action hook is triggered by a system event like
initialization or the posting of a new event. You could set an action
hook to send a welcome email to each new user who registers and
provides an email address.
One thing I hadn't seen in the open source documentation, prior to
reading this book, is the Shortcode API, which allows you to put a
simple placeholder on a page and have it replaced at runtime by some
custom content. For example, [gallery] might be a placeholder for a
photo gallery and [gallery id="123" size="medium"] might be a way of
placeholder for a specific photo, where the attributes will be passed
to the function responsible for retrieving and sizing the image. In the
Fancy Archives example, Prelovac uses a shortcode placeholder on the
page where the archives will appear.
I've also looked at the similar system of hooks and add-on modules
in Drupal, another popular open source content management system, but
the WordPress API strikes me as being just a little cleaner and
simpler. My sense is that Drupal is probably more powerful but makes it
harder to do the simple things. I know there is a fierce debate along
those lines between fans of these two platforms, and I don't expect to
settle it.
But this book convinced me WordPress can be extended to do just
about anything I would want to do on the web. Once I had done the tour
through Prevlovac's examples, I found it much easier to start looking
through the code of other publicly-available plug-ins and figuring out
how they work as well.
Very useful.
Only registered users can write comments. Please login or register. |