WordPress - Debug Techniques

Adding code to WordPress produced one of the slowest and most painful debug cycles I have ever experienced. It takes almost 2 minutes per cycle. My current best guess is that there is a memory leak in JavaScript, jQuery (written in JavaScript), or some other JavaScript library. At any rate, periodically restarting the browser helps a lot.

Much of the data presented below was developed by starting with a working plugin and trying to modify it for my use. Normally, errors produced when using this approach are easy to find ... but not with WordPress ... what a disaster.


echo - Display text and variables

The primary technique is to simply output some text that says "I am here" - it just indicates where the code is executing.. It is also useful to see what the values of some variables are. Because these are displayed in the web page, adding spaces or a little html will make the output easier to read. If you uses double quotes, then variables will be converted and linebreaks (\n) will work. In various routines, you would add code similar to the following and display the results via

For those messages that flash by too fast to read, try Ctrl-Shift-PrtSc (to capture a screen image) and then paste into Windows Paint (under Accessaries/Paint.)


DEBUG Flag

When starting out, database errors were exceptionally hard to debug. The information in this section should help a lot.

You could add ** define('WP_DEBUG', true); ** to your wp-config.php file - I haven't tried this yet.

In the wpdb constructor

These are used in wp-db.php The following is from wp-settings.php, it controls the display of php errors If you don't want to bother editing wp-settings.php, then placing the following in your code (and calling it) will enable database errors to be displayed A database error example (I had to capture this as an image using Ctrl-Shift-PrtSc) My problem turned out to be using the wrong operator for creating an array.


var_dump

Sometimes, particularly with complex data types, echo won't display anything. In these cases, try var_dump. Using the simplexml example, var_dump displayed However, since the actual formatting (in the html file) was the data can be displayed on more than one line by encapsulating var_dump in <pre> tags. As mentioned above, in this case, the echo command did not print anything.


Author: Robert Clemenzi
URL: http:// mc-computing.com / ISPs / WordPress / Debug.html