After my last post, I spent quite a while looking for and reading resources on writing WordPress plugins. There’s a lot of good information out there, but I found that it doesn’t all agree and it seems that there are several ways of accomplishing things. Anyway, here’s a few resources I found that helped me get started:
- The Codex – As usual, The Codex provides a great starting point, explaining the concepts. There are also links throughout the page such as Adding Administration Menus and I18n for WordPress Developers, which go into more depth on specific topics. Check out the External Resources at the bottom of the page too.
- Devlounge Plugin Writing Series – This is a twelve part series on writing a plugin, which covers getting started right through to release. It is a few years old now and I didn’t find every section helpful but it gives a good framework on which to build. The series is also available as a PDF.
- 10 Common Coding Mistakes – I found this a really helpful article as it forms a good checklist of things to avoid doing, especially if, like me, you aren’t really sure what are the correct / best / most secure ways of doing things.
I decided to start out with my plugin by getting the basic functionality of the admin screens working. This was quite a simple process, which the Devlounge series (linked above) explained well.
The admin screens allow you to add a Google Calendar feed with various options such as the number of events to retrieve and whether or not to show events in the past. You will then be able to use the feeds (hopefully!) to display a list or grid in a page or as a sidebar widget.
I’ve also added the ability to edit or delete a feed. Here’s a screenshot of what things look like so far. Remember this is just the basic functionality to allow me to add feeds for testing the rest of the plugin, I’ll tidy everything up before release.
There’s still quite a bit to do regarding security and things like that, but I don’t think the admin screens are looking too bad. I’m not sure about the name ‘Google Calendar Events’, I just can’t think of anything else yet.
So, after getting the admin stuff basically working, I decided to move onto looking at the widgets I want to produce, specifically one to display a small calendar grid with events information.
I found a nice little script by Keith Devens, called php-calendar, to do all the complicated date / grid magic, which simplifies things quite considerably. I’ve adapted it a little bit to suit, but basically I just call:
generate_calendar( $year, $month, $days, //Array of days that have events $day_name_length, //1 = 'M', 2 = 'Mo', 3 = 'Mon' etc. $month_href, $first_day, //0 = Sunday, 1 = Monday etc. $pn //Array of information for prev / next month links );
and it returns calendar grid markup based on the feed data that the plugin parses. Here’s how it’s looking so far in the default theme with a bit of CSS:
I also haven’t looked at inserting grids / lists into a page, but I should be able to use the same php-calendar script as used in the widget to do the hard work for the page grid. I’ll need to do some research into shortcodes too.
So far, so good I’ve got a lot to do yet before even thinking about a release, but it’s coming along nicely.
Update – I have now developed and released this plugin (Google Calendar Events). Take a look at the plugin homepage for more details.