More Dates in WordPress
Initially, I just threw a script link in the footer of my Time child theme but that’s not really how you’re supposed to do things in WordPress Land and it meant that a pretty useful action would be restricted to that single theme. There are also some people in the AddThisEvent comments requesting WordPress plugins. Since I’m wandering around the borders of Programistan anyway, I figured I’d write a plugin. This may be beating a dead horse in terms of detail but I’m hoping it might help other people who aren’t programmers get things done.
The first version was as barebones as you can get. It does via plugin what I did previously via the theme – stick the addthisevent script in the footer. I referenced the WP wp_enqueue_script2 page in the codex to do this. You can see it commented up below.
This second version gets a tiny bit more adventurous. I think it follows the WP practices better in that it first registers the scripts and then enqueues them. It’s also registering two additional elements – the custom preferences js for addthisevent and some custom CSS (provided by addthisevent3) to make the events look a bit prettier than the default. You can see the preferences and custom CSS options delineated on the addthisevent page but it’s one of those one page themes that make it difficult to link to the elements. You can see the details in the comments below. The main pieces were looking at wp_register_script and both wp_register_style and wp_enqueue_style. I didn’t initially notice the difference between how you’d do that with scripts vs styles. It matters.
Version 3 Plans
Next up is a settings panel and using wp_localize_script to allow people to change the CSS and preference options.
The addthisevent syntax (as well as the larger post) is being generated via a Gravity Form. The addthisevent format is below. And you can try it out here.
<a href="http://example.com/link-to-your-event" title="Add to Calendar" class="addthisevent"> Add to Calendar <span class="_start">10-05-2015 11:38:46</span> <span class="_end">11-05-2015 11:38:46</span> <span class="_zonecode">35</span> <span class="_summary">Summary of the event</span> <span class="_description">Description of the event</span> <span class="_location">Location of the event</span> <span class="_organizer">Organizer</span> <span class="_organizer_email">Organizer e-mail</span> <span class="_facebook_event">http://www.facebook.com/events/160427380695693</span> <span class="_all_day_event">true</span> <span class="_date_format">DD/MM/YYYY</span> </a>
The submission builds the date button, adds a picture, and creates a map via shortcode using the aptly named Simple Google Maps Shortcode Plugin. I’m not happy with the map functionality at the moment because clicking on the marker doesn’t allow you to select “get directions.” I was initially using WPMU’s Google Map plugin (which does that) but didn’t like how it only showed the map on the full post. If I can’t find something that does this well it may be time to write another plugin.