This is a concept paper that describes a very simple plugin that handles event management in WordPress.
Q: There are hundreds of plugins doing exactly this — why a new one?
A: All the plugins I tested are more complicated than needed. I tried many of them. I think that my concept is more simple, more robust and more flexible. :)
The basic concept
– An event is defined by it’s start and (optionally) end date (and optionally start and end time).
– Those dates should be handled by ordinary custom fields, holding the date/time information as a string, like this: “
– Being simple custom fields, we can attach start/end dates to anything we want: to posts, to pages, or to custom post types.
– The plugin shouldn’t handle the way those dates are presented on the public site: this will be entirely managed by the theme.
How will the theme use the dates?
Since our date stamps are in a machine-readable format, the theme can make use of the following functions:
get_post_meta() to check if items have start and end dates.
meta_compare to query for specific date ranges, like this:
$meta_query = new WP_Query( array( 'meta_key' => 'Start Date', 'meta_value' => $today, 'meta_compare' =>'>=', 'orderby' => 'meta_value', 'order' => 'ASC', ));
– use the
date_i18n() functions on start and end dates in order to display them exactly as we want.
The role of the plugin
Until now, all the things we described could be used as an event management system that works completely without a plugin. :)
So the role of the plugin is only to improve the usability for the end user.
– will offer a clean interface for setting start and end date.
– will enable us to restrict dates only to specific post types, if we want. This could be defined in some admin panel, or more simply in the functions.php file.
– will prevent mistakes, like wrongly formated dates.
WordPress already offers an interface for setting date/time information: we see it in the publication date field of each post. It’s actually a dropdown menu and simple input fields: not a revolution in terms of interface design, but it’s perfectly usable.
In order to keep the interface consistent, the most logical thing is to use exactly the same design for our date system (rather than adding some flashy jQuery date picker, like most plugins tend to do).
Here is a mockup of how the date management interface should look like:
1) Initial state.
2) Entering a start date (without time information).
3) The start date has been saved.
4) Entering an end date.
5) The end date has been saved.
And here you can see how this would integrate with the post edition interface:
Are there other features that the plugin should be able to handle?
Yes, a few:
- Optional times: the plugin should allow that the user leaves the date field empty. The
strtotime() function will render an empty time field into 00:00. I would tend to solve this in the most simple way, by testing for a 00:00 time stamp in the theme, and not displaying the time if that is the case.
- Localization: the plugin must be localized, through the standard .po / .mo files, so that it can be adapted for other languages. There won’t be much translation work, as the interface is really minimal.
- Repeating events: sooner or later the need for repeating events will appear. Technically, this shouldn’t be too difficult: we need just another custom field, that holds a date/time string, or an array of date/time strings. We also need to add to the mockup a button that allows to add a repeat.
Here is how it could look like:
And here we are editing the Repeat date:
Finally, here is how it would look like with several repeats:
Are you interested in this idea? Are you able to help me developing this plugin? Then please get in touch – immediately! :-)
Update: the plugin is already there, has been successfully tested, and will be publicly available soon, thanks to the great work of Vlad and Dan at Dream Production.
Update (2012-10-10): the plugin is on GitHub. No real documentation yet, but it’s coming.
Update (2012-10-29): There is some basic documentation now, with more code examples coming.