WordPress, Jetpack stats graph, and broken images in the admin bar – and a solution

Get ready for it, this is…a blog post about a blog.

I recently upgraded to WordPress 3.5.1, the upgrade went off without a hitch, save one problem.  The sparkline graph from the Jetpack plugin was displaying as a broken link.  If you’re not familiar with the term “sparkline” don’t worry, I didn’t know what it was called until I started doing searches.  The sparkline is a small traffic graph that appears in the admin bar when  you’re logged into your WordPress account; it shows your site traffic for the last 48-hours.

After looking all over the web, in the WordPress and Jetpack forums I found people with similar issues, but none of their resolutions fit my particular issue.  I tried disabling plugins one at a time, that made no difference.  I deactivated Jetpack and then linked it again. No difference.  Removed Jetpack altogether and reinstalled, same result.

Through the WordPress forums I was able to get in touch with Jeremy, a Happiness Engineer with Automattic who helped me figure out the root cause. Big thanks to him for taking the time to work with me. Here’s how we diagnosed the issue.

View the xmlrpc.php file in the root of your WordPress directory with a web browser. It should return the text “XML-RPC server accepts POST requests only.”  If that message is the first line of the page, then your problem may lie elsewhere.  If there are any empty lines or spaces above that message then you have a php script introducing whitespace before the headers are printed, and Jetpack hates this. That additional whitespace could be coming from plugins, themes, or any custom hacks to the WordPress core.

Since I had already disabled all the plugins, I knew it couldn’t be coming from them.  Next up, switch back to the default theme. When I did that the sparkline appeared right away, so it was something in the theme, so the next step is to go through all the php files in the theme and look for empty lines before the php tags, or empty lines between closing and opening tags, functions.php would be the most likely location.

In my case, there were so many included files in the functions.php file that it was becoming quite tedious to look through them all and since a theme update was available I went ahead and tarballed up the directory and ran the update. Result? Graph is back and everything is happy.

I found a useful piece of shell code online that quickly searches for leading and trailing empty lines in files, might come in handy if you decide to search for yourself:

for f in `find . -type f`; do
for t in head tail; do
$t -1 $f |egrep '^[ ]*$' >/dev/null && echo "blank line at the $t of $f";

Happy Bug Hunting!

3 thoughts on “WordPress, Jetpack stats graph, and broken images in the admin bar – and a solution

Leave a reply below!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s