For a while, we’ve been working on a stand-alone web server for doing WordPress development. We started working on it for a few reasons:
- We wanted a way to see debug information without cluttering up the theme or breaking or altering the layout
- We wanted a way to get more visibility on WordPress’s internals, without overwhelming ourselves with junk
- We maintain a lot of sites, and we only check their wp-content directories into source control. We wanted a way to have one set of WordPress core files with a bunch of checked out wp-content directories for different sites, and to run them all without having tonnes of vhosts in Apache
- We wanted a way to get up & running when working on a new site with the barest minimum of fuss
With all those in mind, we started writing some software to wrap around PHP 5.4’s built-in webserver. It accepts requests, figures out where they should go, and hooks into the WordPress core to retrieve and display debug information. It also captures PHP errors, so that they get displayed on your console instead of mushing up your theme — very useful when you’re working on a plugin written by someone who (naughtily) codes with notices off (don’t do that).
With all that in mind, here’s a rundown of some of the useful things Whippet can do.
Serving up pages
The simplest way to invoke Whippet is to move into a working WordPress installation, and run it:
harry@harry-laptop:~$ cd Code/wordpress/ harry@harry-laptop:~/Code/wordpress$ whippet Whippet version 0.1 ALPHA started at 12:32:53 on 07-08-2012 Written and maintained by dxw. Visit http://whippet.labs.dxw.com for more information. Found a WordPress installation at /home/harry/Code/wordpress Listening on localhost:8000 Press Ctrl-C to quit.
By default, Whippet’s output relates to things which are going on in your theme and plugins. You’ll see what template WordPress wanted (and which one it got). You’ll see the parameters that WordPress parsed from your URL. You’ll see the contents of any queries that were executed as a result of something called from a theme or plugin. You’ll also see the static assets that the site loads.
If you want to understand what the core is doing, there are some extra options that you can pass to Whippet:
harry@harry-laptop:~/Code/wordpress$ whippet --show-wp-queries --show-wp-errors
With those selected, Whippet will also display the queries that WordPress itself is generating, along with any errors that pop up. It’s quite a lot of output, but certainly useful when you’re tracking down obscure things.
Actions and filters
One of Whippet’s most useful features is the visibility it gives you on the hook callbacks that are being executed. We’ve sometimes had really horrible bugs on sites with lots of plugins because hooks are interacting in ways that the authors did not expect.
With Whippet, it’s easy to see exactly what’s going on:
harry@harry-laptop:~/Code/wordpress$ whippet --show-hooks wp_head Whippet version 0.1 ALPHA started at 12:49:02 on 07-08-2012 # snip 12-08-07 12:49:04] Hook triggered: Action wp_head called from function wp_head in /wp-content/themes/twentyeleven/header.php at line 66 [2012-08-07 12:49:04] 1: wp_enqueue_scripts in /wp-includes/script-loader.php at line 682 [2012-08-07 12:49:04] 1: noindex in /wp-includes/general-template.php at line 1704 [2012-08-07 12:49:04] 2: feed_links in /wp-includes/general-template.php at line 1622 [2012-08-07 12:49:04] 3: feed_links_extra in /wp-includes/general-template.php at line 1622 [2012-08-07 12:49:04] 8: wp_print_styles in /wp-includes/functions.wp-styles.php at line 20 [2012-08-07 12:49:04] 9: wp_print_head_scripts in /wp-includes/script-loader.php at line 643 [2012-08-07 12:49:04] 10: rsd_link in /wp-includes/general-template.php at line 1678 [2012-08-07 12:49:04] 10: wlwmanifest_link in /wp-includes/general-template.php at line 1688 [2012-08-07 12:49:04] 10: adjacent_posts_rel_link_wp_head in /wp-includes/link-template.php at line 1224 [2012-08-07 12:49:04] 10: locale_stylesheet in /wp-includes/theme.php at line 1125 [2012-08-07 12:49:04] 10: wp_generator in /wp-includes/general-template.php at line 2127 [2012-08-07 12:49:04] 10: rel_canonical in /wp-includes/link-template.php at line 2252 [2012-08-07 12:49:04] 10: wp_shortlink_wp_head in /wp-includes/link-template.php at line 2315 [2012-08-07 12:49:04] 10: twentyeleven_print_link_color_style in /wp-content/themes/twentyeleven/inc/theme-options.php at line 383 [2012-08-07 12:49:04] 10: _custom_background_cb in /wp-includes/theme.php at line 1767 [2012-08-07 12:49:04] 10: twentyeleven_header_style in /wp-content/themes/twentyeleven/functions.php at line 203 [2012-08-07 12:49:04] 10: recent_comments_style in /wp-includes/default-widgets.php at line 613
When the specified hook runs, Whippet will display a list of all the callbacks, their priorities, and where they’re defined. When you’re specifying the hooks you want to see, you can give a list, or use a regular expression:
harry@harry-laptop:~/Code/wordpress$ whippet --show-hooks wp_head,init harry@harry-laptop:~/Code/wordpress$ whippet --show-hooks 'wp_.*'
As with the reset of Whippet’s output, it will only normally display hooks that have executed as a result of something done in a plugin or theme. But you can make it display core hooks as well, if you need to:
harry@harry-laptop:~/Code/wordpress$ whippet --show-hooks the_title --show-wp-hooks
Managing lots of sites
This may only be useful if you manage a lot of sites and have a workflow similar to ours, but it does make life easier if you do.
We have numerous wp-content directories checked out of source control, like so:
Wordpresses - Client1 - plugins - themes - Client2 - Client3 ... - ClientN
With whippet, you can move into one of those client directories and run it directly, without it needing to be within a WordPress installation.
If Whippet detects that it’s running from a wp-content directory for the first time, it’ll prompt you to set your database configuration, download a copy of WordPress to a shared location, and hook everything up so that it just works. You can also specify the version of WordPress you’d like Whippet to use, which makes testing on different versions a synch.
How to get started
At the moment, Whippet only works on Linux and MacOS. Our apologies to Windows users! We’d like to make it work there too, but that might require some Windows developers to volunteer some help.
If you do use Linux or MacOS, visit the Whippet page on Github for full installation instructions. Remember, Whippet is still Alpha software! So do expect to find the odd bug. We’ll do our best to get things fixed quickly. And we’d love to know what we could add to make your WordPress development easier.