FIRST ATTEMPT AT A WORDPRESS PLUGIN, THE IDEA

As I mentioned earlier, I’m having a go at writing a WordPress plugin, which is something I’ve never done before. The reason I’m doing this is that I can’t find a plugin or other solution that will display Google Calendar data on a WordPress site I am developing quite the way I want.

The functionality I need is fairly similar to the ICS Calendar plugin, in that I need a full page calendar grid, containing events. However, I may also need a widget type thing to display a smaller grid or list of a few upcoming events and ICS Calendar can’t do this. Najlepsze golarki elektryczne

I was hoping to use .ics files as the sources of calendar data for my plugin, as this would mean that it could be used with other calendars, rather than just Google Calendar, but I can’t seem to find a robust, reliable .ics parser and I don’t fancy writing my own. So, I’ll only be dealing with Google Calendar XML feeds and parsing them with SimplePie, which, rather handily, is included in WordPress installations.

Also, I came across SimplePie GCalendar, which provides some handy helper methods for dealing specifically with Google Calendar feeds. Chwilówki

So, after finding all these bits and bobs and messing about with some code, I have a better idea of what I think the plugin will be able to do, here’s a list:

Display a calendar grid containing events on a page
Display a list of events on a page
Display a small grid of events in a sidebar widget
Display a list of events in a sidebar widget
I’m also hoping that it will be able to handle multiple feeds, so you could have a full page calendar displaying data from one feed, and then a sidebar widget displaying a list of upcoming events from an entirely different feed, for example.

I definitely have a more solid idea now of the functionality and I can sort of picture how it will work in my mind. Now I just need to find out how the heck to write a WordPress plugin… to the Codex!

Update – I have now developed and released this plugin (Google Calendar Events). Take a look at the plugin homepage for more details.

FIRST ATTEMPT AT A WORDPRESS PLUGIN, RELEASE!

Google Calendar Events is released!

It took a lot longer than I expected and I think I should have started out with something simpler. I’m reasonably pleased with it, but I can see that there is a lot more work to do yet before it is polished. Tabletki na odchudzanie

I originally set out to make a plugin to suit just my requirements for a website I was working on, but I’ve ended up adding various features that I don’t really need, like widgets, lists and AJAX (I just needed a full page calendar grid). I think this may have been a mistake as it will take a lot more work to maintain and develop the plugin, and it may end up being a Jack of all trades but master of none.

Developing the plugin was definitely a good learning experience. I have improved my PHP skills quite a bit, learnt a lot more about WordPress and got to grips with SVN.

I’m definitely enthusiastic about making more plugins now, but perhaps that enthusiasm will wane when the bug reports start rolling in for this one 😛

You can download the plugin from the WordPress plugin directory, if you like.

I’ve also set up a plugin homepage on my site where any feedback about the plugin can be left.

THINGS I’VE LEARNED LATELY

I find it difficult to think of good subjects on which to write blog posts. Well, often I’ll have an idea or solve a PHP problem or find a useful tool, or something of that nature and think ‘I’ll write a blog post about that later!’. But when it comes to actually writing something, I usually can’t think of enough to say to warrant / deserve of full blog post, so just give up. kolokacja

So, in an effort to keep at least a little blogging output going, I’m going to post a ‘Things I’ve Learned’ list every once in a while. These will just be bits and bobs of information to do with work, PHP, WordPress, web design, life in general… anything really that I have discovered. Although I suspect much of it will be things I should probably already know 😛

Here we go, the first list, in no particular order:

printf() and sprintf()
I finally got around to implementing internationalization in my plugin (well, sort of, it doesn’t completely work yet) and found that these PHP functions come in rather handy for inserting runtime values into strings that need to be translated. I always knew these functions existed, but was only vaguely aware of their purpose. I imagine they will come in handy for all sorts of things.
ActionScript LocalConnection() is broken on Macs in some releases of Flash Player 10
I have spent a long time over the last week or so putting together a Flash based, multi-platform CD-ROM. I was working with some old SWFs, built using Flash 5 and ActionScript 1, so had to make use of LocalConnection() to get things communicating properly. This worked fine for a while, until I came to testing on a Mac, only to find that the version of Flash Player used in creating the Projector files appears to have a problem with LocalConnection(). What a pain! I have tried the isPerUser fix mentioned, but to no avail as yet.
Tony Hawks Pro Skater 2 for iPhone is awesome!
I loved THPS2 on PlayStation 1. I’d so far as to say it was my favourite PS1 game. I was a bit worried that the iPhone version would be rubbish, but so far it’s great. The controls work really well, although the accelerometer controls aren’t brilliant. My only other crtitcisms would be the soundtrack, which isn’t even remotely as good as the old one, and the lack of the skatepark builder (but I guess this may have been too fiddly to use on the iPhone).
I need some new socks
Lots of mine have holes in them.
CRB checks take a long time
My new job is in a school, so I am required to have a criminal records check before I can start work. It takes forever! It must have been 4 or 5 weeks now since it was sent off. I’m getting slightly worried that they have unearthed my axe-murdering past.
That’s it for now. More anon.

THINGS I’VE LEARNED LATELY, 2

Phew, such a busy week. Work deadlines, family coming over, all sorts of stuff. I’m feeling pretty tired, but next week looks a bit quieter. Anyway, here’s another ‘Things I’ve Learned’ post.

  • Flash is a pain
    I have been using Flash a lot in the past week or so and have run into several very annoying bugs. A few times, seemingly at random, it ‘forgot’ where my ActionScript class files were, even when they were in the same directory as the <code.fla< code=””>. Much yelling ensued. I didn’t ever really figure out why it happened, after a while it just worked again. Very frustrating when you have a deadline! Don’t even get me started on the Mac specific bugs and issues. Lets just say that I’m glad I don’t have to do much more Flash work for a while!</code.fla<>
  • Regular expressions
    I have been meaning to learn about regular expressions for a while now. Before, to me, they just looked like a bunch of gibberish that would take ages to learn, but actually the rules are fairly simple to get to grips with. I think they are going to come in very handy in the next stage of development of my plugin. There’s still a lot to learn, but it seems a little less insurmountable now.
  • Tax returns are complicated
    I’ve never seen so many questions I don’t know the answer to since the A-Level Physics exam.
  • I’d really like a proper internet connection
    I live in one of the only places in the UK that still can’t get a ‘proper’ broadband internet connection. I’m stuck with one of those USB mobile dongle thingies. It’s slow and unreliable and just rubbish in general. I get a little envious when I see people complaining in blogs / forums about their ‘slow’ 20Mb connections. I’m sure I spend half my time looking at loading bars moving imperceptibly rightwards.
  • I want a Mac
    I can’t afford one, I don’t need one. But still…

More soon

SIMPLE RECENT POSTS SHORTCODES FOR WORDPRESS

(Update – 21st February, 2012 – I’m no longer using this on my site, but the method still works)

Over the last couple of days I have been working on updating my site’s theme. More specifically, I have been converting it to a Hybrid child theme.

I created my original theme from scratch, and it wasn’t particularly brilliant in terms of construction. I basically had a separate template for every page. I somewhat missed the point, methinks. I have leaned a lot about WordPress development since then, so decided it was time for an update.

I wanted a simple way of adding the various bits and bobs to the homepage (recent posts, flickr images, twitter) that didn’t involve hacking about with template files. Here’s what I did for the recent posts section:

Really Simple

There’s a handy function built into WordPress: wp_get_archives(). A first glance, it doesn’t look like it’s going to be very helpful for displaying recent posts, but by passing it a few arguments, it becomes very helpful indeed. All the possible arguments are explained on the Codex, but the interesting ones are:

type – setting this to postbypost means the function retrieves posts ordered by date
limit – the number of posts to retrieve
echo – this should be set to 0 (false), for reasons explained below
So, to retrieve the 5 most recent posts, I used the function as follows:

wp_get_archives( 'type=postbypost&limit=5&echo=0' );
To output this where I wanted, I could have just dropped it into the template file in the appropriate place, but as mentioned earlier, this is what I want to avoid. So I made use of the WordPress Shortcode API. It’s really easy to use. I won’t explain the basics of shortcodes here, the Codex entry explains it well.

Simply adding the code below to my theme’s functions.php allowed me to use the shortcode [recent-posts] wherever I liked.

function my_recent_posts_shortcode() {
return '

    ' . wp_get_archives( 'type=postbypost&limit=5&echo=0\n\r\c' ) . '

';
}

add_shortcode( 'recent-posts', 'my_recent_posts_shortcode' );
Notice that I manually wrap the output of wp_get_archives() in a

    , the function doesn’t do this for you. The reason for echo=0 can be seen here too: the list needs to be returned, not directly echoed, so that it is output in the correct spot.

    I also added a class attribute the the

      , so that I could style it as I liked.

      This functionality could be extended slightly, by using more features of the Shortcode API, which would allow us to define the limit argument of wp_get_archives() in the shortcode itself, rather than hardcoding it. Like so:

      function my_recent_posts_shortcode( $atts ) {
      extract( shortcode_atts( array( 'limit' => 5 ), $atts ) );

      return '

        ' . wp_get_archives('type=postbypost&limit=' . $limit . '&echo=0') . '

      ';
      }

      add_shortcode( ‘recent-posts’, ‘my_recent_posts_shortcode’ );
      The shortcode could then be used like this:

      [recent-posts limit=”3″]
      Where the limit attribute is the number of posts to retrieve.

      This shortcode could be used on a post, a page, or even in a Text widget.

      More Complicated, but Flexible

      The above is great and works well, but I decided that I wanted a bit more customization of the output, specifically the ability to show the publish date of each post. This required a different approach. Here’s the code to be added to functions.php

      5 ), $atts ) );

      $q = new WP_Query( 'posts_per_page=' . $limit );

      $list = '

        ';

        while ( $q->have_posts() ) {
        $q->the_post();
        $list .= '

      • ' . get_the_date() . '' . get_the_title() . '' . '
      • ';
        }

        wp_reset_query();

        return $list . '

      ';
      }

      add_shortcode( 'recent-posts', 'my_recent_posts_shortcode' );
      ?>

      As you can see, the shortcode stuff remained the same. The wp_get_archives() function has been replaced with a custom query, which allowed me to build up the list markup however I required.

      The value of the limit attribute from the shortcode is passed to the WP_Query object as the value of its posts_per_page parameter. This limits the number of posts retrieved in the same way as before.

      The while loop simply goes through the posts returned by the query, generating the markup, which could of course be customized in any way.

      wp_reset_query() is called to ensure that this doesn’t mess up the main WordPress loop, or other custom loops that may be processed later.

      There are a multitide of possible parameters that can be passed to WP_Query, so this could easily be adapted to retrieve posts from a certain category, or from all categories except one, or from a specific author, or whatever is required.

GOOGLE CALENDAR EVENTS, 0.7.1

This is just a bug fix release, nothing particularly exciting, I’m afraid. Here’s a quick overview of the changes:

Weird AJAX Bug

An odd bug was causing AJAX enabled calendar grids to disappear, or just get stuck loading, when navigating between months. It took me quite a while to replicate it, which was very frustrating, as several people had reported the same issue but I had no idea what was going on!

Anyway, I finally tracked down the problem. It was due to me being an idiot and not really understanding how preg_replace_callback works.

Stupid Timezones

Timezones are confusing. If I ever make another plugin, please remind me to make sure it has nothing to do with dates and times.

Hopefully, this release should fix an issue causing all-day events to continue to be displayed even after they have ended.

Tooltip Date Title Bug

In some cases, the title settings for AJAX grids were being ignored during AJAX requests. This release should fix that too. Many thanks to S. Wyatt Young for bringing my attention to this problem.

Output Sanitisation

Output sanitisation was a bit lacking in some places, but should be much improved now.

Caching Empty Feeds

Previously, the plugin did not cache feeds that returned no events. This meant that if you were displaying a list or grid of events from several feeds, one or more of which were empty, HTTP requests would be made for the empty feeds on every page load, which is slow.

Many thanks to everyone who reported the above issues, and helped with testing the fixes. It is very much appreciated!

As always, bug reports, feature requests and any other feedback can be left in the comments on the plugin homepage, or on this post.

GOOGLE CALENDAR EVENTS, 0.7.2

It’s been a long time since I’ve updated Google Calendar Events. I’ve had very little time to work on the plugin lately, due to other projects that have had to take precedence.

A couple of months back, I did begin a major rewrite of the plugin, with all sorts of snazzy improvements, but it’s a long way off release worthy, or even beta worthy, at present. I’ll continue to work on it when I can, but I thought I’d better fix a couple of minor (yet annoying) bugs in the current version for the time being.

The fixes in 0.7.2 are as follows:

There was an issue with the “More details” Google Calendar page link. The URL wasn’t constructed correctly, which resulted in the event details defaulting to the UTC timezone. This only affected the simple display options (not the event display builder), but is fixed now.
Previously, setting the cache duration to 0 would be ignored, causing caching to still occur. Setting this to 0 should now work correctly.
With FORCE_SSL_ADMIN enabled, the plugin’s Ajax requests would fail in most cases, preventing month navigation. This shouldn’t be the case any longer.
Also, an issue brought up in the WordPress core Trac recently made me realise I’d been using the wrong method (an incorrect hook) for enqueuing the plugin CSS and JavaScript, which could potentially cause an issue with the newly released 3.3 version of WordPress. I don’t think the issue would have affected Google Calendar Events, as I had is_admin() checks in place, but better to be safe (and correct) than sorry!

Before updating, remember that if you’ve made any changes to the main plugin stylesheet (google-calendar-events/css/gce-style.css), you should take a backup first, as changes will be overwritten during the update. If you’ve used the “Custom stylsheet URL” method instead, you shouldn’t need to worry about this!

You can download the update from the plugin directory, or simply update from your WordPress admin.

Feedback, bug reports and feature requests are always welcome. You can add a comment below (or on the plugin homepage), or send me an email.

Thanks!

A FRESH COAT OF PAINT

I’ve been wanting to redesign my site for a while now. The old design was looking… old, and to be honest, pretty cringe-worthy.

When I created the original design, I was just getting stared with WordPress, so didn’t fully understand the theme development process. I’ve certainly learnt a lot more in the last couple of years.

So, here’s the new design!

I’m more of a coder than a designer, so I decided to keep things simple and clean, with plenty of whitespace (or greyspace?). You might even call it “minimal”, possibly?

It should be pretty speedy, too. I’ve kept HTTP requests to a minimum, making use of as much CSS3 snazziness as possible.

Try it on your iPad / phone, it’s responsive too!

Anyhoo, I’m quite pleased with it, I think. It turned out to be one of those projects where you’ve been working on it for so long that you can no longer decide whether it’s brilliant, awful or somewhere in between.