Classy Plugins

I was asked a few weeks ago why I structured my WordPress plugins the way I do.

Anyone who has spent any time looking at my code knows that I like to keep my main functions in a class and wire up action hooks and filters in the root of the plugin.  But few people have asked me why I set things up this way.

My explanation is in two parts:

  1. Writing clean code
  2. Writing easy-to-maintain code

Though it should be noted now that, while this particular development style makes heavy use of classes within PHP, this is not object-oriented programming.

Let me say again – this is not object-oriented programming.  I use classes often to define custom objects, but in this situation I use them merely as convenient wrappers for code. Continue reading…

Start with a Unit Test

Unit Test Results in Visual Studio

Not everyone is a fan of test-driven development.

Writing unit tests for your code can be a laborious task, and it has no immediate benefit to your customers.  So why waste any time writing the tests, write?

This past week, a colleague of mine summed up the problem pretty well:

I’ve finished writing the code for that feature.  Now I just need to take some time to sit down and write some unit tests for it.

Unit Test Results in Visual Studio

He’s not following test-driven development.  Instead, his tests come in as an afterthought.  Actually, most of us code this way.

We write a chunk of code to perform a task.  Then a customer asks for a new feature, so we write some more code.  Then a new hire comes in to the company demanding we take some time to go back and document our existing code base with unit tests.

It’s not fun. It’s not glamorous.  It feels like a waste of time.

But I still feel it’s the way things should be done. Continue reading…

Theme-ready Widgets in WordPress

Core contributions widgets in the sidebar of my personal site.

If you use WordPress, you’ve probably used a handful of widgets in your sidebar. Some display statistics.  Others print out recent comments.  Others display posts related to the content in the main window. But all of them do this in the exact same way.  They take some data, wrap it into a hard-coded HTML template, [...]

Continue reading...

Javascript Event Listeners

Sample Userlist

Most websites today are stuck in the mud. They sit there, present content, and fail to solicit any interaction from the user.  This site is no exception.  I write content, you read it.  End of story. But some websites are far more interactive.  They present rich, immersive interfaces and simulate the kind of interactive behavior typical of [...]

Continue reading...

Dependency Injection and Abstract Interfaces in C#

If you’ve ever written code, you’ve probably written a unit test.  If you haven’t written unit tests, you should start. Now. Really. Unit tests let you quickly verify that your code is operating in a predictable fashion.  When you make changes down the road, you re-run the same unit tests to make sure nothing broke. [...]

Continue reading...

Show off Your Codex Props!

Show off your contributions to the WP Codex in your own sidebar.

Some time ago, I released a plugin that allows you to highlight contributions to the core WordPress project on your very own site. Today sees the release of version 1.2 of the WP Core Contributions Widget plugin.  This new version adds a Codex contributions widget as well. So now you can show off both your [...]

Continue reading...