How to Debug WordPress Query

WordPress offers the best across the board and easiest debugging tools available. Many users simply do not take the time to see what is available to them. The hard work has been done. By exploring the WordPress site and exploring the tools predesigned, much of the work and frustration is eliminated. These tools are designed to help you monitor your site and get rid of the things that cause you issues. Usually those things are caused from third party plugins. By spending a little time in the WordPress Codebase you will find life just got much easier. The customization that is available helps you design a site that you can work with efficiently and errors and warnings can be dealt with quickly and easily. WordPress is so popular, that finding someone to assist if never more than a few clicks away.

Not debugging your site or not correcting offending issues, even if hidden will affect your site performance. It can take up needed memory and reduces performance. It also will use up disk space. Your goal is to produce an error free site. These tools will get you as close to that as is possible.

As with any system, you will need to debug PHP code. WordPress has a built in debugging system to make this process much easier. We are going to describe multiple tools for debugging WordPress. We will also discuss a standardize code that functions across plugins, themes and the core.

It is highly recommended for code developers to account for WP_DEBUG in plugins and themes. Though it is not mandatory, it is advised to use WP_DEBUG mode while writing and standardizing code planned to be released publically. This insures the plugin and theme is compatible with the code of other developers. If it is not compatible it is impossible to use and will prevent your theme from being promotable via WordPress tools on the WordPress official site. It insures the integrity of your code as well.

WP_DEBUG (as well as other debug tools) are meant for local testing and staging installs. They are not recommended for use on live sites.


The Blog Millionaire Podcast

The top rated blogging podcast on iTunes is hosted by Brandon Gaille. He built his blog from zero to 1 million monthly visitors in less than 18 months, and he shares his secret strategies in his award winning podcast. Listen to the Latest Episodes Right Now.

WP_DEBUG is a permanent global (a PHP constant) which can be used to prompt the mode of debugging throughout WordPress. By default it is usually set to true in the wp-config.php file in the development copies of WordPress. Before WordPress 3.1, the constant was “STYLE_DEBUG” but is did not affect JavaScript. It affected only CSS files. In 3.1 the two constants were merged and now affects both types.

Define ‘WP_DEBUG’ true

Define ‘WP_DEBUG’ false

Do not add apostrophes around the words (true/false)

PHP Notices, Errors and Warnings

By enabling the WP_DEBUG system, al PHP errors, warnings and notices will be displayed. This is assumed to adjust the default of the system of PHP with only shows fatal errors. It also will sometimes show a blank white screen when an error is reached. For this reason the modification was made. Due to this modification, sometimes an error will display when nothing seems to be amiss. Usually that means proper data validation conventions inside the PHP were not followed. Once the code has been identified these warnings are an easy fix resulting in code that is easier to maintain.

There may be functions or function arguments within WordPress that your site is currently using that may be slated for deletion in the near future. Enabling WP_DEBUG will activate notices about the coming deletions and often will suggest a new function that should be used in its place. When the currently used functions are removed from the core code, the change will be seamless for you as it was already addressed.

WP_DEBUG_LOG

A companion to WP_DEBUG is the WP_DEBUG_LOG. This program causes all errors to be saved on a debug.log file inside wp-content/directory. This is for use in the instances when you want to view or review all the notices generated while off-screen. WP_DEBUG must be enabled (true) in order for WP_DEBUG_LOG to function.

The code below, placed in your wp-config.php file, will record (log) all errors, notices, and warnings. It logs them in a file called debug.log in the wp-content directory. It will also hide the errors.

You must insert this BEFORE /* That’s all, stop editing! Happy blogging. */ in the wp-config.php file

// Enable WP_DEBUG mode define(‘WP_DEBUG’, true);

// Enable Debug logging to the /wp-content/debug.log file

define(‘WP_DEBUG_LOG’, true);

// Disable display of errors and warnings

define(‘WP_DEBUG_DISPLAY’, false);

@ini_set(‘display_errors’,0);

// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)

define(‘SCRIPT_DEBUG’, true);

WP_DEBUG_DISPLAY

This companion to WP_DEBUG controls whether debug messages are shown inside the HTML of pages or not. The default is ‘true’ which shows errors and warnings If you wish to hide the errors and warnings, set this to false.. Use this with WP_DEBUG_LOG so that errors can be reviewed

later.define(‘WP_DEBUG_DISPLAY’, false);

SCRIPT_DEBUG

SCRIPT_DEBUG will force WordPress to use the “dev” versions of core CSS and Javascript files rather than the minified versions that are usually used. This is a good idea when you are testing modifications to any built-in .js or .css files. The default is false.

define(‘SCRIPT_DEBUG’, true);

SAVEQUERIES

Savequeries saves the database queries to a group or array. That selection can be displayed to allow you to evaluate those queries. The queries explains the cause, the length of time to execute and what function called the query. Be sure to turn this function off when you are not debugging. It will have an impact on your site.

define(‘SAVEQUERIES’, true);

Wordpress Statistics