8 Things to Check When Reviewing a WordPress Theme (part 2)

5. Documentation

While ideally code would be readable without much documentation – if function names describe what the function does, and variable names are descriptive of what the variable contains – in reality, adding comments to the code makes it much easier to understand. The comments also help when you’re returning to code months or years later and trying to understand why a feature exists.

DocBlocks are the most helpful guide to how a function should be used, and again, the WordPress PHP Standards have an excellent guide to using these.  Having the DocBlocks in place helps to clarify why a function exists – it provides an easy-to-read reference on what a function does, and clearly shows what should be passed in to the function and what it will return. I’ll often write the DocBlock before I write any code for the function itself, so that I have a clear understanding of what I’ll be implementing before any code exists in the function.

6. Accessibility

Accessibility has become more of a concern for developers in recent years, and rightly so. We should try to make our site usable by as many people as possible, and that includes people with difficulty using certain devices, the blind, the deaf, and people sensitive to motion – for just a few examples.

Some examples of things to check for include appropriate color contrast, helpful focus states, and keyboard navigation. Try testing out the site in different ways – installing a screen reader browser extension and navigating the site with the screen reader on is one way to help this process.

Vox Media has recently published the accessibility guidelines that they use for their own products – I would recommend adding these to your development and QA processes to ensure that accessibility is kept in mind while developing.

7. Checking return values

This is a check that I often see overlooked in PHP functions – the function relies on either an argument being passed to it or a return value from another function that gets assigned to a variable. Then, without checking the variable, the variable is used. Often, this will work fine, because you’ll remember to pass it the correct value, until it doesn’t.

You’ll often spot these in the debug.log file, once you’ve enabled WP_DEBUG: the “Undefined variable” notices are usually from these situations.

To fix this, you can use a check such as this before using the variable:

Or even better, return early in the function if a variable isn’t set:

8. Front-end load time

For checking load time, I use the tool webpagetest.org. WebPageTest lets you test on a variety of different devices and in different browsers, so that you can even test load times on an Android device with a 2G connection, for example.

From there, you can see a waterfall view of how the page loads, and see which resources are slowing down your page load times or adding an unnecessary amount of weight to the site.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.