How Clean is Your Code? | Ed Nailor

How Clean is Your Code?

Print Friendly

WordPress theme developers… How clean is your code?

Did you know that you can find out very easily? Simply enable the following line within your wp-config.php file, and you will see if your code is clean!

define('WP_DEBUG', true);

This will display WordPress warnings and notices.

I recently did this and found a few issues on my main Framework I use for development. Not that there were a lot of issues, mind you, but here were a couple of the notices my theme had:

Notice of Deprecated WordPress function: This notice / warning lets you know that one or more of the functions you are using in your WordPress theme is no longer supported by the current version you are using. For example, in a couple places my theme framework used the get_author_link() function. This is no longer valid as of 2.8, and while it still works on 3.0, later versions may not support it at all. The newer version of this function is get_author_posts_url(). A simple find and replace throughout my theme updated the entire theme with the new function, and the warning went away!

Undefined index: This one was a little tricky at first. It was always on a line in which I was checking to see if a $_GET variable was = to something. The problem was that the $_GET variable was not yet set, so the variable was “undefined”. So a quick edit to the code and the error went away:

Wrong Code:

if($_GET['something'] == "something else") { do something special ; } 

Corrected Code:

if(isset($_GET['something']) && $_GET['something'] == "something else") { do something special ; } 

Basically, I just needed to check to see if the variable was set. Since it isn’t set, we move on with no errors.

I challenge WordPress theme developers to use this great tool to check your themes. Code you use today may already be deprecated, so make sure it is all valid before you pass it on! (Just be sure to disable the WP_DEBUG in your wp-config.php file before your site is live!)



Leave a Reply