Doug Sparling

Mobile/Web Developer

Convert mp3 bit rate and change from stereo to mono

by Doug Sparling

I listen to a lot of podcasts, and sometimes I like to keep the files around. However, often a simple audio podcast uses a high bit rate and often stereo, resulting in a large file size when it’s not really necessary. So unless I want the highest quality mp3 file possible, I stick with the BBC Future Media Standards and Guidelines. For podcasts, it’s something like the following:

  • MP3 Mono Speech: 64 kbps, 44.1 kHz, constant bit rate
  • MP3 Stereo Music: 128 kbps, 44.1 kHz, constant bit rate

Here’s a typical FFmpeg command I run to simultaneously convert a stereo file to mono, and to lower the bit rate to 64K: (Obviously, change the filenames as necessary.)

$ ffmpeg -i stereohighbitratefile.mp3 -ac 1 -ab 64k mono64kfile.mp3

HT to Richard Farrar.

Setting user-agent in curl or wget

by Doug Sparling

$ wget --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0" -c

$ curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0" -O

Install the current version of Go in Ubuntu

by Doug Sparling

After running:

$ sudo apt-get install golang

I ended up with an older version of Go than I needed:

$ go version
go version go1

Wanting to use scanner from bufio, I needed Go 1.1. Fortunately, you can get the latest version from

Simply run the following:

$ sudo add-apt-repository ppa:duh/golang
$ sudo apt-get update
$ sudo apt-get install golang

Now verify that you’ve got Go updated:

$ go version
go version go1.1.1 linux/amd64

Install PHP mcrypt extension in MacOSX

by Doug Sparling

In an earlier post, Installing Multiple Versions of PHP on Mac OS X with Homebrew-PHP,  I mentioned using Homebrew-PHP to install multiple versions of PHP. I ran into an issue installing Magento due to the mcrypt extension not being loaded.

PHP extension “mcrypt” must be loaded.

Note: I’m assuming here that you have already checked your php.ini file and uncommented the appropriate line that loads the mcrypt extension.

Using Homebrew, it’s a simple process to get mcrypt added to PHP.

First, tap (which may be unnecessary if you used Homebrew-PHP):

$ brew tap josegonzalez/php

And then do the install:

$ brew install PHP53-mcrypt

This also works with PHP 5.4 (PHP54-mcrypt) and PHP 5.5 (PHP55-mcrypt).

You may be prompted to link:

Error: You must `brew link php53' before php53-mcrypt can be installed

You may also get another error, something like:

Error: Could not symlink file: /usr/local/Cellar/php53/5.3.26/bin/phpize
Target /usr/local/bin/phpize already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
brew link --overwrite formula_name

To list all files that would be deleted:
brew link --overwrite --dry-run formula_name

I didn’t have any issues with this and simply ran:

$ brew link --overwrite php53

If you get an error about not having zlib installed, they try:

$ brew tap homebrew/dupes

Restart Apache and with a little bit of luck you should have mcrypt loaded.

Using cURL to Test the WordPress Theme and Plugin APIs

by Doug Sparling

Occasionally (rarely) when trying to search for a theme or plugin via the WordPress dashboard, you may see an error like this:

An unexpected error occurred. Something may be wrong with or this server’s configuration. If you continue to have problems, please try the support forums.

This means that the request WordPress has made to the theme or plugins api has failed, or that the body of the response is bad or empty. Often web hosts will turn off outbound http requests and this will be the source of your problem. However, there can be a myriad of other issues that may cause this error. WordPress will use one of three “transports” and search for them on your server in this order: curl, streams, and fsockopen. Since the focus of this article is on using cURL, that’s what will use at the command line.

To check if cURL is installed on your server, use the Unix ‘which’ command to find it’s install location.

$ which curl

and you should get a response something like this (your path may vary):


To simply check connectivity with the WordPress theme and plugin apis, you can make an http HEAD request with cURL:

$ curl -I


$ curl -I

You should see output something like this:

<br />HTTP/1.1 200 OK<br />Server: nginx<br />Date: Tue, 15 Oct 2013 14:06:36 GMT<br />Content-Type: text/html; charset=utf-8<br />Connection: close<br />Vary: Accept-Encoding<br />

If you don’t have connectivity, you may see something like this:

<br />curl: (6) Could not resolve host:; nodename nor servname provided, or not known<br />

If you want to duplicate the request made when you’re actually on the WordPress dashboard, you’ll have to make a POST request with serialized data parameters. To mimic a search for a “blue” theme, use this cURL command:

$ curl --data 'action=query_themes&amp;request=O:8:"stdClass":4:{s:4:"page";i:1;s:8:"per_page";i:36;s:6:"fields";N;s:6:"search";s:4:"blue";}'

To mimic a search for a “cache” plugin, use this command:

$ curl --data 'action=query_plugins&amp;request=O:8:"stdClass":3:{s:4:"page";i:1;s:8:"per_page";i:30;s:6:"search";s:5:"cache";}'

A successful request will return quite a bit of HTML and serialized data (which I won’t post here).

Contributing to WordPress

by Doug Sparling

Contributing to an Open Source project is fun. (and it’s good for you!) Not only that it’s educational. I can’t tell you how much I’ve learned by answering questions in the Support Forums (you can find me here), doing an occasional bit of work on the WordPress Documentation Team, and writing and releasing a handful of WordPress plugins.

As you can see, there are many ways to get involved and contribute to WordPress. (and I’ve just done a few of them) Whether you’re a WordPress developer, theme author, or just simply a fan or user of WordPress, there’s probably a way you can contribute.

And one important point I’ve neglected to mention…you’ll be helping others and you’ll be helping WordPress! And I don’t have to tell you, but by giving back to the fabulous WordPress community you’ll make the world just a little better place than it was before.

If you’re interested (and I hope you are), I’ve curated a few links to help you get started. – Codex

Make WordPress –  Make WordPress Core






If you got any additional resources, don’t hesitate to send them my way.

Moderate Use of Shortcodes in WordPress

by Doug Sparling

In a recent question on the forums a user wanted to know if there was a way to prevent non-admins from using shortcodes when creating/editing posts.

The solution I came up won’t prevent non-admin users from entering shortcodes, but it will prevent WordPress from saving them.

Add this to your theme’s functions.php:

function filter_handler( $data , $postarr ) {
    if ( !current_user_can( 'manage_options' ) ) {
        $data['post_content'] = preg_replace( "/\[([^\[\]]++|(?R))*+\]/", "", $data['post_content'] );
    return $data;
add_filter( 'wp_insert_post_data', 'filter_handler', '99', 2 );

This will prevent anyone other than admin/superadmin from inserting shortcodes (well, it will delete a pair of square brackets and anything in between when a non-admin inserts or updates a page/post – if there’s a better way I haven’t found it yet).

WordPress Posts Page ID

by Doug Sparling

To find the ID of the page that contains the posts (the listing of posts), you use the WordPress function:


The caveat is that this value will only be set if you assign a static page as your front page and assign another page as your posts page (via Settings->Reading). When you run WordPress where the front page displays your blogs posts, that’s a special case and there is no “posts page” id. (actually, it comes back as 0).

$posts_page_id = get_option( 'page_for_posts' );
echo "page id: " . $posts_page_id;

WordPress 3.6.1: How To Upload swf Files

by Doug Sparling

If you have tried to upload a swf (or exe) file and gotten an error message something like this:

“filename.swf” has failed to upload due to an error
Sorry, this file type is not permitted for security reasons.

That’s because WordPress 3.6.1 has added some new security restrictions in regards to file uploads (

Additional security hardening:

Updated security restrictions around file uploads to mitigate the potential for cross-site scripting. The extensions .swf and .exe are no longer allowed by default, and .htm and .html are only allowed if the user has the ability to use unfiltered HTML.

And while it’s best to take these security changes seriously, in come cases you may need to upload a swf file (or an exe, but I’d never see a need to do that). So if you’d like to allow uploading of a swf file via the Media Manager in WordPress 3.6.1, just add this code to your theme’s functions.php file:

function add_upload_mime_types( $mimes ) {
    if ( function_exists( 'current_user_can' ) )
        $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
    if ( !empty( $unfiltered ) ) {
        $mimes['swf'] = 'application/x-shockwave-flash';
    return $mimes;
add_filter( 'upload_mimes', 'add_upload_mime_types' );

Installing Multiple Versions of PHP on Mac OS X with Homebrew-PHP

by Doug Sparling

When developing WordPress plugins I always test with different versions of WordPress, but I generally just use my default version of PHP (5.3.26 in my case). I had a case where a PHP function had been deprecated in PHP 5.3 and removed from PHP 5.4, so I wanted to test my plugin with PHP 5.3, 5.4, and 5.6. Homebrew-PHP by Jose Diaz-Gonzalez and other contributors couldn’t make it any easier. Just follow the link for some Homebrew goodness: