First Plugin!

I’ve written and contributed my first ever plugin! This was in response to a forum post asking for help in getting WordPress.com’s Google Maps shortcode to work. The user had moved over to a self-hosted WordPress.org and all the previously used shortcodes weren’t working.

My original solution was simply to add in the shortcode and get the shortcode handler to throw out the <iframe> code. The width and height was hardcoded and the ‘View Larger Map’ link wasn’t there, but the maps showed.

The very first draft of the plugin can be found in the pastebin.

The release version of the plugin supports variable widths and heights for the maps. It does this by finding the width and height of the original <iframe> then appending those values to the end of the URL stored in the shortcode, just like how it’s done on WordPress.com.

When the URL is parsed for output, those values are extracted and used to define the dimensions of the <iframe>.

Another important step which had to be taken was to move the execution of the shortcode up, before wpautop is called. If not, linebreaks will not be added correctly, causing the layout in the post to go haywire. Code to do this was adapted from http://www.viper007bond.com/tag/wpautop/

After all this talk, I’m sure you want to know where to find the plugin. It’s been uploaded to the official plugin repository.

I’ve also created a page on this blog which explains its purpose.

If you find it useful, do leave a comment and tell me about it 🙂

Allowing Automatic Updates

My LAMP setup asks for FTP credentials when I try to use the auto update functionality. That’s a pain because I haven’t figured out how to setup FTP on my server yet. Sure it’s just a Google search away, but I would like to get the auto update to work seamlessly.

After setting up suPHP on my web host, auto updates now work on my production sites. So file permissions seem to be the key to the whole problem. The web server user must have write access to the WordPress directory. This post here explains the process WordPress goes through to check if an auto update can be performed successfully. It also provides the simplest solution.

Open a terminal window and type the following command. This assumes that the web server user is www-data. In the case of Ubuntu and Apache on my setup, it is.

sudo chown -R www-data <WordPress folder>

Now when I update plugins automatically, it downloads and applies the update all by itself! Super convenient!

Adding Google Analytics

I suddenly had the urge to know how many visitors my site is getting. I had added Google Analytics code manually to the other site, but didn’t have it on the main church site.

Logging in to Google Analytics and getting the code was easy, the problem was how to put it in. The instructions said to put it before the </head> tag, which implied putting the Javascript into a .js file and using wp_enqueue_script() to put it in. I decided to google a bit to see if this is the best way to insert the code.

Of course there are already plugins to do this. I decided to try the one by Joost (http://wordpress.org/extend/plugins/google-analytics-for-wordpress/). The options are pretty comprehensive and it seems simple enough to use. I just had to type in the UA number and that’s it!

Now to wait and see if it starts tracking successfully.