Page 7 of 9

Developing the future of podcasting

Almost exactly a year ago I released Seriously Simple Podcasting, a podcasting plugin for WordPress that does exactly what it says on the tin – makes podcasting simple. I originally wrote the plugin for my church website because, despite the few options available for WordPress, I couldn’t find a functional and non-bloated podcasting solution anywhere.

After a number of updates to the plugin over the last 12 months, nearly 17,000 downloads and exclusively 5 star reviews on the plugin repo, the time has come for a massive overhaul of the code – the end result of which will be v2.0 of the plugin. My primary goals with v2.0 are threefold:

  • Refine/refactor the code so it is more versatile and easier to maintain
  • Make sure the plugin is fully extensible
  • Document all the things

With v2.0 of the plugin I will also start releasing extensions that will enhance the existing functionality with optional extras. While these extensions will be available for purchase for the most part, the core plugin itself will always be 100% free.

If you would like to get involved in the development of Seriously Simple Podcasting v2.0 you can check out the GitHub issues list for available tasks – feel free to add further issues and I will decide if they need to be part of v2.0 or not. Please use the release-2-0-0 branch and send any pull requests there – all contributors will be credited in the changelog.

[button link=”https://github.com/hlashbrooke/Seriously-Simple-Podcasting/issues?milestone=1&page=1&state=open” window=”yes”]GitHub Issues List[/button] [button link=”http://wordpress.org/plugins/seriously-simple-podcasting/” window=”yes”]Download Plugin[/button]

WordCamp Cape Town 2013

Since the beginning of the year, myself and a few of the guys from WooThemes have taken over the organising of the WordPress Cape Town community. Over the course of the year we have organised two local meetups – one for WordPress’ 10th Anniversary and the other just because we thought the community deserved it. They were both very different meetups – one being a cocktail party (with cake!) and the other being a more traditional meetup where we heard from two local entrepreneurs about how they set up their businesses on WordPress. You can see the videos from these meetups here.

wcct_logo_bwNext up for the local WordPress community is none other than WordCamp Cape Town 2013 – to be held on 7 November at the Cape Town Stadium. This year’s WordCamp has the (somewhat loose) theme of ‘The Business of WordPress’ and each of the talks will be looking at building a website, app or community on WordPress. We’ll be hearing some interesting stories from local success stories, such as Lazygamer and One Page Love, as well as how a number of people have used WordPress to grow their careers and get their unique working situation up and running. The full schedule for the day is available here: http://2013.capetown.wordcamp.org/schedule/.

Not only do we have 7 incredible local speakers (although one of them is from Joburg, but don’t hold that against him), but we also have 3 international speakers who will be joining us from across the Atlantic. You can see the full list of speakers here: http://2013.capetown.wordcamp.org/speakers/.

On top of that we have a top notch after party planned for all the WordCamp attendees: http://2013.capetown.wordcamp.org/2013/10/18/announcing-the-official-wordcamp-cape-town-2013-after-party/.

The day promises to be an absolute winner, packed with fascinating talks and an excellent chance to meet some of the great people that make the WordPress community what it is.

[button link=”http://2013.capetown.wordcamp.org/tickets/” size=”large” window=”yes”]Book your ticket now![/button]

WordPress: Random post order with correct pagination

Randomising the order of the returned posts in a WordPress query is easy – simply add  'orderby' => 'rand' to the arguments and you’re good to go – this is great, until you need to paginate the results. As soon as you navigate to the second page of the results, the posts are returned randomly once again and you get an entirely different set of posts that may or may not contain posts that you have already viewed – if you’ve experienced this before then you’ll know exactly how frustrating it can be. After having this problem numerous times myself I decided to find a way around it.

The first thing we need to do is make sure our PHP session is initiated. You will see the reason for this in the function itself, which is where the magic happens – here we will use MySQL’s RAND() function and supply it with a seed value so it uses the same random order on every subsequent page load. To do this we will store a random string as a PHP session variable so it can be used by MySQL as a reference for the order to use for each page. All we need to do is add this snippet to our theme’s functions.php file:

You will notice one extra operation on line 7 of this snippet – we also reset the seed value every time the first page of the posts are loaded. This means that as long as someone stays on the paginated pages they will see a consistent set of results, but once they go back to the first page the randomisation will reset and they will see the posts in a completely different order.

Note that in this example I have limited the ordering to the front page only (that is, the home page of the site when the front page is set to show your latest posts), but you can change the conditional to target any page or post type archive that you like.

Storing snippets in Gist

Gist has been around for ages as a service provided by GitHub to store and share code snippets for any language. I’ve been using it for a while, but only as a way to quickly share snippets of code with people. I’ve now decided to change that a bit and make better use of the service – as a result I have added all my snippets from this blog to my Gists and I will continue to add even the smallest snippets as I develop them. So from now on whenever I work out a useful snippet of code I will add it to Gist whether I blog about it or not.

Easily generate a month select box in PHP

Having a drop down menu for month selection is a relatively common need, but it can be a pain to write from scratch each time. Here’s a short snippet that will generate a select input (drop down menu) for all 12 months of the year – the option values will be the month numbers with leading zeros:

To remove the leading zeros, simply remove the line with the str_pad() function.

Seriously Simple Podcasting – User Survey

In December last year I released a podcasting plugin, descriptively named Seriously Simple Podcasting, that I originally built for use on my church’s website – it’s been just over 4 months since I released it and, at the time of writing this post, it has been download 5345 times. It is currently sitting at v1.4.6 and is now at a point where it is entirely stable and there are no bugs or niggles that are holding it back. Since I released the plugin I have been offering free support using the support forum built into the WordPress plugin repository and things have been moving along smoothly with every support ticket resolved so far.

I have been pleasantly surprised by the uptake and popularity of the plugin so far, so I have decided to do some quick customer research into what features people would like to have added to it and to see whether or not there is a market for releasing a premium version of the plugin with some of these new features. I put together a quick survey asking some open questions about this, so if you have enjoyed the plugin and you have a spare minute please go ahead and fill it out – the more responses I receive the better!

[button link=”http://wordpress.org/extend/plugins/seriously-simple-podcasting/” window=”yes”]Download the plugin[/button] [button link=”https://docs.google.com/forms/d/1PbMBocuGZq4K_LV2dL-GfmAJwNlsT76HUbr5fgRZxfo/viewform” window=”yes”]Fill out the survey[/button]

A .gitignore file for multiple WordPress sites in one repo

After holding off for a while, I finally got round to moving all of my client projects into a single (private) GitHub repo and the whole process was a lot less painful than I expected it to be. In the end, I only had one issue and that was crafting my .gitignore file so that the WordPress core files for each project didn’t all get uploaded to my repo (that would be a sure way to upset the fine folks at GitHub). The file wasn’t too tough to get right, but I thought it worth sharing in case anyone else is struggling with the same thing.

So here is a .gitignore file that will exclude all WordPress core files from your repo so that only your themes and plugins will be uploaded – this works recursively, so that it will ignore all the copies of WordPress you have in the sub-folders of the repo.

Code template for a WordPress plugin

I’ve been working on a lot of plugins lately – many for my work at WooThemes and a few for my personal projects – and over time I have developed a standard code base from which I start any of my new plugins. I always keep this handy for any new work, so I don’t have to rewrite the same basic code every time I start something new. I’m sure many people have their own similar frameworks for this kind of thing, but I thought it worth sharing my own in case it helps someone else get started with new plugin development. The template includes built-in support for:

  • Custom post type with custom fields and custom taxonomies
  • Plugin settings page
  • WPML i18n

The code is entirely object-oriented and is written according to the WordPress coding standards – all it requires is editing in order to remove the demonstration data and add new, more functional, data. The plugin is obviously not meant to be used in its current form, but if you activate it without changing anything it will create a new post type (identified as ‘*Posts’ in your dashboard menu) and a new settings page (found at Settings > Plugin Settings). These pages are entirely functional, so you can see a working demonstration of how a plugin built using this template will work. You can get the code from GitHub below – feel free to change it to make it more practical for your own use.

Get the code!

Simple animated scroll for jQuery

If you use links to navigate to other elements on the same page, it’s generally a good idea to animate the scrolling so you don’t disorientate your users. There are jQuery plugins (such as ScrollTo) that offer many different ways for handling this, but if you don’t want to mess about with all the features of a new plugin then this snippet will be very useful. It’s a simple function that will scroll your page to any DOM element that you specify:

As you can see you can also specify the speed and a top offset for the scroll (I find this top offset very useful as default behaviour puts the target element flush with the top of the browser, which can make things feel a bit cramped). An added bonus is that it appends the target string to the current URL, so if you are using a standard anchor reference (such as #element) then users will be able to grab the URL and it will point to the correct location on the page. If you are using other selectors to target an element then I would recommend removing the function inside the animate call.

Totally simple jQuery method for selecting all checkboxes in a form

It’s a common problem with a dozen different solutions – if you’ve ever needed to add a ‘select all’ checkbox to a form in order to make your users’ lives easier then you’ll have searched for a simple way to do it. If you’re using jQuery here’s a very simple method that’s as easy as can be:

You can replace the form identifier with whatever container you choose (fieldset can be useful if your form is split up like that). This code will cause all the checkboxes in the form to be toggled when you toggle any checkbox that has the selectall class.

Simple.

UPDATE: Modified code to be slightly more efficient as suggested by Jamy Golden.