WordCamp Toronto: Saving Time by Managing WordPress from the Command Line (WP-CLI)

Shawn Hooper presenting WP-CLI at WordCamp Toronto 2014 (Photo Credit: Melissa Jean Clark)

Thank you to Melissa Jean Clark for snapping a few pictures during my talk.

On Sunday, I had the honour of getting to speak at WordCamp Toronto, a 2 day conference full of developers, designers, and users of the WordPress platform.  It was my first time giving this talk about the WP-CLI library, and I couldn’t have asked for a better audience.  My “talk” turned into more a group discussion.

The video of the talk will be online at some point, but in the meantime, you can see the slides here:

I also wanted to share  chunk of code that I used during the talk.  It’s my script to create a new WordPress installation from the command line, assuming you have permissions in MySQL to CREATE DATABASE.   I only recommend doing this in a development environment.

wp core download
wp core config --dbuser=root --dbname=$1 --dbpass=vagrant
wp db create
wp core install --admin_user=wcto --admin_password=wcto --admin_email=me@example.com --title="WordCamp Toronto" --url=http://localhost/$1/

Running this script, for example:

./newsite demosite

from the command line will:

  1. Download the WordPress core
  2. Create a wp-config.php file
  3. Create a database using the connection details specified in step 2.
  4. Go the “5 minute” install of WordPress – in seconds.

Once this runs, you can login to your dashboard, you’re ready to go.

US President Barack Obama Issues Statement in Support of Net Neutrality

Today, the White House released a statement from President Obama in which he puts his support behind Net Neutrality – the concept that Internet Services providers cannot limit, throttle, or charge extra for access to some content.  All content must be treated equally.  For example, your ISP, who might also be a cable company, shouldn’t be allowed to throttle your access to Netflix.

See the full statement here:

How to Search and Replace in your WordPress Database

Database search

Search and Replace. Find and Replace.  Whatever you call it, we’ve all had to do it at some point or another.

When it comes to swapping out one string for another in WordPress, you need to be careful.  Some values are stored in the database as serialized arrays.  They look like this:


(This example is the wp_capabilities field in wp_usermeta)  If I were to do a search and replace, or an UPDATE in SQL, to change ‘administrator’ to ‘subscriber’, I would break things.  This particular array expects the string where ‘administrator’ is written to be 13 characters long.  To properly update this field, I would also have to change the s:13: before administrator to s:10: (the word subscriber is 10 characters long).  What a pain, right?

The good thing is, there’s a few solutions out there to help you do a safe search & replace in WordPress.   I’ll show you my two favourites below.

Why you’d need to do this?

The most common search and replace I do in WordPress is when moving my database from a production website to my local development environment.   The site’s domain name is scattered throughout posts, widgets, plugin settings, etc. It’s not as simple as just updating the Site URL in the WordPress settings screen.  example.com has to be replaced with localhost in a million different spots (ok, maybe I’m exaggerating a little bit).

Solution #1: Interconnect IT’s Search & Replace Tool

Screenshot of Interconnect IT's Search & Replace Tool for WordPress

Interconnect IT has made a great web-based tool for safely replacing values in WordPress’ database without breaking serialized arrays.

Once you download the search/replace tool from their website, place it (or upload it) in a new folder at the root of your WordPress site, the name of the folder does not matter.  Navigate to the folder, and the tool will run, automatically capturing the database connection details from your wp-config.php fie.

A few of the great feature about this tool are:

  1. It supports regex, so if you’re that kind of ninja, you can do some pretty powerful searching.
  2. You can do a “dry run” – where you will get to see how many changes would be made in each table.  It’s a great way of catching mistakes before doing seriously damage.

Don’t say you weren’t warned:  More than once, this utility reminds you that once you’ve completed your search & replace, make sure to delete to tool!  If someone else were to stumble upon it, they could destroy your site. (They’d also have your database credentials, since they’re right there on screen)

If you want to leave the utility installed, I’d suggest protecting it’s folder with an .htaccess file.


Solution #2: Search & Replace using WP-CLI

My preferred method of doing a search and replace is to use WP-CLI.  If you’ve never used WP-CLI, it is a set of command line tools that allow you to manage your WordPress site(s).   Not everyone will be able to use this method, you need to be hosted somewhere that supports WP-CLI.  Most shared hosts don’t, as they normally block SSH access to their servers for security reasons.  I do know that SiteGround and GoDaddy both support it now.  Of course, if you have a dedicated server or a virtual server with someone like Digital Ocean or Linode you can install it easily.

Once you have WP-CLI running, doing a search & replace is as simple as typing this:

wp search-replace old-value new-value

As with Interconnect IT’s utility, you can also do a dry-run, to make sure you’re only changing what you need to.  Simply add the –dry-run parameter to your command, like so:

wp search-replace old-value new-value --dry-runScreenshot of the results from a WP-CLI Search and Replace

Of course, with WP-CLI, you can (and should) backup your database before doing such an operation:

wp db export mydbbackup.sql
wp search-replace old-value new-value --dry-run

You can also restrict the search and replace to specific table names, ignore specific fields, or replace throughout all sites in a WordPress Multisite Network.  If you need more help with this command, just type:

wp search-replace --help

That’s it!

Both of the methods shown there are much safer than doing an UPDATE in MySQL, or a Find & Replace in a .SQL dump of your database.   Good luck, and happy replacing!

Twitter Analytics Now Available to Everyone

Twitter Analytics Graph

As a fan of Twitter, and of data, today is a good day.  Twitter’s analytics tool, which had previously only shown some data to regular (read: not advertisers) users of it’s service, has opened it’s full set of reports up.

In addition to statistics about your followers, which has been available for some time, you now get access to analytics for every tweet you’ve sent, including:

  • The number of times your tweet as appeared in someone’s Twitter feed.
  • The number of engagements (opens, favorites, replies, hashtag tickets, retweets, etc.) that the tweet has received
  • The engagement rate (as a percentage) of the tweet

Screenshot from Twitter Analytics showing impression and engagement rates on every tweet.

You also get a summary of the engagement that all of your tweets has had over the past 28 days, compared to the previous 28-day period.

Twitter Analytics 28-Day Summary

If you want to get started looking at your stats, visit:


The Happiness Bar

Volunteers sitting at a table with laptops assisting WordCamp attendees

I’ve just returned from WordCamp Montreal 2014, a two day gathering of WordPress users, designers, developers and practitioners in fields related to the incredibly popular publishing platform. (Did you know that WordPress now powers 22% of all websites?)

Aside from the informative sessions, the abundance of networking sessions, and some great meals too one of the highlights of a WordCamp for me is something called The Happiness Bar.

The Happiness Bar doesn’t serve up your favourite alcoholic beverage, but it does quench your thirst for knowledge. Staffed by volunteers (actually, everything at WordCamp is volunteer), the Happiness Bar is a place to drop in an ask any questions you might have about WordPress.

There are a couple of great reasons to volunteer at the Happiness Bar:

  1. You get to help. I volunteered for two one-hour shifts at the bar on the weekend, and was able to help a food blogger migrate her website from wordpress.com to a self-hosted solution, giving her the flexibility to do more with her site. I was also able to teach an aspiring developer a few tricks to writing cleaner code.
  2. You get to see some of the great projects that people in the community are working on.
  3. You end up learning some great tips and tricks from your fellow Happiness Bar volunteers.

If you’re attending your local WordCamp, I suggest you take the time to visit the Happiness Bar – either to ask a question, or to lend a hand.

SOLUTION: Moving NeatWorks NeatReceipts data directory

I recently purchased a new computer with a solid-state hard drive as the operating system/applications drive.   It isn’t a great idea to store your data on these drives, so with each application install, I make sure that it stores its data to my secondary (SATA) hard drive.  When I got to configuring my NeatWorks NeatReceipts scanner software, it turns out there is no way to change the default data directory through the application’s preferences.  (Rumours have it that version 5 of the NeatWorks will allow this).

I’ve found a workaround to this problem.  You can create a directory junction (type of symbolic link) in Windows that will make the Neat software look in its default location (C:ProgramDataThe Neat CompanyNeatWorks) but access files in a new location.  Please note that this fix will only work on Windows Vista, Windows 2008, or Windows 7 and newer. Older version of the operating system did not include this functionality.

To set this up:

  1. Move your NeatWorks data folder to it’s new location (for this example, I’m moving ito to D:NeatWorks)
  2. Go to your command prompt (Start Button, Run…, “cmd”)
  3. Change Directories to The Neat Company folder:

    cd "C:ProgramDataThe Neat Company"

  4. Create the symbolic link to your new data location:

    mklink /J "NeatWorks" "D:NeatWorks"

Start NeatWorks and you should see all your data.

The Dark Side of Domain Name Expiration

A client recently decided to let an old domain name of theirs expire.  It was not the domain name they were using on the e-mail, print materiel, etc. any longer, and saw no reason to keep paying the registration fee.

A few weeks later, this decision would turn out to be a big mistake.  Their old domain name was purchased by a company selling adult products

When a domain name expires, there is a 30 day grace period during which nobody can register the domain, except for the original registrant (just in case you forgot to renew!)  Your domain name will stop resolving (it can’t be used), but you can still renew the domain through your registrar.

After this period, the domain name is made available for registration by anyone who wants it.  In the case of .ca domains, the Canadian Internet Registration Authority (CIRA) posts a list in advance of “to be released domains”, making the discovery of these soon to be available gems even easier.  There are also many services online to discover expired domains.

In my client’s case, there were many websites out there containing links to their old website, which now, embarrassingly, took visitors to this adult content.

What To Do?!

There are several things that you should do before letting an old domain name expire that can help avoid embarrassment like this, or potential loss of business if, for example, a competitor were to register your old domain!

  1. Keep the domain nameDomain name registrations are (usually) cheap – anywhere from about $5 a year, to $30 a year, depending on your registrar.  Some TLDs for foreign countries charge higher fees, the price range quoted here is for domains in Canada or the US.   An expense of $150 over 5 years to keep your rights to an old domain may be worth it!
  2. Configure your domain to redirect users properly

    If you’re planning on no longer using a domain name because you’re replacing it with a new one (maybe your company changed names?) then make sure users visiting the old domain are redirected to the new domain!There are tools that scan websites looking for links that don’t work, or that have changed.  This is done by automatically visiting each link on the page and checking for the HTTP Response Code that comes back. There are many types of responses, but the important ones for this discussion are:

    200 – OK.  This link works, and it returned
    301 – Permanent Redirect
    404 – File Not Found

    If you simply add your new domain name to your web server’s configuration, and don’t setup your old website to redirect to the new address (Response Code 301), tools that check links will see a response code of 200, everything OK.  The owners of the sites will never be altered that they should update their links.

    You could also notify users of your website that the address has changed so that they can update their bookmarks (favorites) in their browser.

  3. Use Google’s link: search to find websites that link to your domainThere’s a little known feature in the Google search engine that allows you to find web pages that link to your domain name.  Simply Google for “link:<your domain>” to get the list.

    Click here for a list of sites that link to my blog’s domain

    With this list, you can then work on contacting the owner of each website to request they update their links with the new domain name.

  4. Update content within your own siteHow many documents on your own website contain links to the old domain name?  Don’t forget to check in files such as PDFs, PowerPoint presentations, Word Documents, etc.   These could be links to web pages, to staff e-mail addresses, etc.
  5. E-Mail SignaturesMake sure the staff in your organization have updated their e-mail signature files to include the new link, and new e-mail addresses if appropriate. The same would be true for their business cards!

As you can see, there are steps you can take to help minimize the risk while changing domain names and letting the original one expire.  It just requires a little planning beforehand.

If your domain name does get taken, the other possible route you could go is to dispute the domain name registration with the governing body for the domain name in question.   For .com, .net and .org domain names, this would be the Internet Corporation for Assigned Names and Numbers (ICANN).  For .ca domain names, this would be the Canadian Internet Registration Authority (CIRA).  They both have domain name dispute resolution policies.   I have never tried fighting a registration using these policies, but it may be worth a try.  The policies can be found here:

Best of luck!

Disney’s Vero Beach Resort

Disney's Vero Beach Resort

Image courtesy of @karenhooper

A few weeks ago my wife, my parents and I had the opportunity to stay at Disney’s Vero Beach resort in Vero Beach, Florida.  It is located approximately two hours from the Orlando International Airport.

This is the first time that we’d stayed at a Disney Vacation Club property that was not located at one of the Disney Theme Parks.

The rooms:

The rooms (we had studio rooms) at the resort are quite nice.  The had a double bed, a pull out sofa, and a small kitchen area with a coffee maker, microwave, and fridge.

Being a bit of a geek, two other very nice amenities in these rooms are that they have Wi-Fi (free for DVC members) and that the alarm clocks in the rooms are iPod docking stations!

There is no room service available in these rooms – although we were able to order a pizza to the resort without any problems.


There are LOTS of activities to take part in at Vero Beach.  If you’re there with children, you may have wanted to go to the bonfire sing-a-long they were hosting (with smores!!). We elected to spend our evening relaxing in the hot tub instead.  The pool area is very nice, and being the beginning of November, was fairly quiet as well.


There are two restaurants on site (one a little pricier than the other).  They’re quite good.  Our only criticism is that the air conditioning was way too cold – although we’ve found this to be the case with the southern United States in general.

Tip: If you’re a DVC member, you get a discount in the restaurants.


The customer service at the resort was excellent, which was not a surprise given the property is in the Disney family.  The check-in process was identical to checking in at the Walt Disney World theme park.  Same room key cards, same “celebration” pins (we got our 1st visit pins for this resort), same friendly smiles.


If golf is your sport, I recommend checking out the Sandridge Golf Course, located only a few minutes from the resort.  We played 9 holes of each of their two courses during our stay and had a great time.

Overall Rating: 4/5  — This is a great place to go if you need a few days to relax after the constant “go, go, go” of being at the theme parks.

Oscar’s Music

Oscar Peterson Statue outside the National Arts Centre in Ottawa

Oscar Peterson Statue outside the National Arts Centre in Ottawa I was walking by the National Arts Centre with a friend at lunch today, and noticed that there’s a new (or at least I’d never noticed it before) addition to the tribute to Canadian Jazz pianist Oscar Peterson.  Above the statue of Oscar at the piano are two speakers quietly playing his music onto Elgin Street. There also appears to be two small spotlights, I can only assume the statue is lit at night.

Has anyone seen this at night?

I thought that was a unique addition to this tribute.