March 11, 2011

It’s certainly been a long time coming, but we’ve finally published a plugin to the WordPress plugin repository.

Mogul Custom Functions is a collection of handy functions that we use on a daily basis to speed our custom theme development.  It’s aimed at theme developers who are looking for a set of simple tools for quickly generating content within their themes.

So what’s in it?

There’s five functions in there.

  • mog_get_outside_id() – to quickly find the ID number for the current page (solves internal loop issues)
  • mog_quik_title() – provides a quick way to return a link with the permalink for a post/page and it’s title
  • mog_in_hierarchy() – checks to see if a page is in a given hierarchy to enable inclusion of content for a given page anscestor/descendants tree
  • mog_simple_sidebar() – outputs a list of pages using wp_list_pages(). Traverses to top level parent and outputs a list of it’s children. (for sidebars)

The fifth is one called mog_long_excerpt() (orignally just long_excerpt()).  I’m not sure of the origins of this script though I can safely say it’s not ours.  This provides an automatic excerpt for use in WP loops, up to a given number of characters, stripping out markup and ensuring that full words are not truncated.

For more information on the individual functions, see the plugin page at plugins.mogul.co.nz

Where did this plugin stem from?

As is a typical natural progression for a WordPress developer, I’ve gone from writing elaborate PHP scripts as “one-offs” in individual template files, through to putting my scripts into a theme’s functions file so they can be re-used within that theme.  From there I moved on to creating stand alone plugins that can be implemented on any WordPress site.   For those that attended WordCamp NZ 2010 in Auckland, you may recall me discussing this progression in my presentation.  Through each progressive step I’ve taken as a developer it’s made implementation of custom code easier and easier.

So, back to the real question: this function set originated from a bunch of scripts that I quickly discovered formed the basis of our functions.php file for every custom WordPress theme we built.  I extracted them out into a stock plugin that I started install as a matter of course when setting up client’s WordPress installs.  The problem with this is that with every install I performed, I added a stock set of plugins from the WordPress repository (one-click simplicity) then I had to FTP up the Mogul Custom Functions plugin each time.  Versioning became a serious issue too – every time I updated the code in the plugin I then had to FTP a new version up to the site I was working on – not to mention the 20 odd other sites I’ve put the plugin on.

Welcome to the WordPress SVN Repository

I know that we’ve got a couple of plugins under development at the moment and one of them is potentially huge.  So I don’t want to blow the delivery of the plugin by making some sort of noobish mistake with a code submission process that I don’t understand.  Unleashing Mogul Custom Functions into the wild gave me the perfect excuse to test out the whole process.  It’s fairly straight forward really, so long as you understand the concept of subversion and have a decent SVN client.   If (like me five hours ago) you don’t understand Subversion, there’s a great guide on wpaddict.net showing how to get your plugin published.  (As an aside I can totally recommend TortoiseSVN).

And now?  Well now we can install our plugin on any WordPress site from the “Add New” option of the plugins menu and also get the major benefit of WordPress plugin versioning – one click upgrades.

Where to next?

Next I’m prepping an update to Mogul Custom Functions which:

  1. wraps mog_simple_sidebar() up into a WordPress Widget for use by slightly less techy WordPress users
  2. Includes a “beer me” feature in which users of the plugin who find it useful can donate to the Mogul beer fund

This will make the functionset ready for use by non theme devs (and get us free beer).

If you’re a theme dev, feel free to install the plugin, give it  whirl and give us some feedback, either here or on the WordPress forum.