WP Debug

WP Debug is a simple WordPress plugin that helps in developers in debugging WordPress themes or plugins.

The five PHP named constants that handle debugging in WordPress are WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY, SCRIPT_DEBUG, and SAVEQUERIES. Those named constants are usually defined in the wp-config.php file.

When the WP Debug plugin installed, developers are given the opportunity to modify those named constants via a simple settings page in the WordPress admin dashboard. Moreover, this plugin comes in handy with two functions that allow developers display debug messages to either the screen or the log file; namely wp_debug () and wp_debug_queries (); by embedding them within their code.

This plugin is intended for local development use only and it is not recommended to be used in a production environment. If this plugin has to be used in a production environment for any reason, then developers have to ensure that they disable/uninstall the plugin and remove any reference to the two functions when they finish debugging the errors encountered.

Download

Click here to download the WP Debug plugin.

Installation

From the WordPress dashboard

  1. Visit Plugins -> Add New
  2. Search for WP Debug
  3. Activate WP Debug from your Plugins page.

 

From WordPress.org or nostraCon.net

  1. Download WP Debug and unzip it.
  2. Upload the wp-debug directory into your /wp-content/plugins/ directory
  3. Activate WP Debug from your Plugins page.

 

If you were unable to activate the WP Debug plugin, it is most probably due to file protection and permissions set to protect wp-config.php. If this happens, the plugin will display a message on the screen to allow you to copy certain lines of code into wp-debug.php and save manually.

Usage

Activating this plugin adds a new page into WordPress settings in the dashboard named WP Debug. This page allows developers to modify the PHP WordPress named constants WP_DEBUG, WP_DEBUG_LOG, WP_DEBUG_DISPLAY, SCRIPT_DEBUG, and SAVEQUERIES via a simple UI.

  1. Visit Settings -> WP Debug
  2. Change the debug settings to your preferences. The section at the bottom of this page shows the changes that will be made to wp-config.php. For more details about these setting visit Debugging in WordPress.
  3. Click Save Changes to save the settings

 

The two functions introduced by this plugin, wp_debug () and wp_debug_queries (), enable developers make debugging calls withing their theme templates or plugins. For example, making this function call

wp_debug (“Smile Please, life is beautiful.”);

Will dislay the following in /wp-content/debug.log

[21-Sep-2015 20:59:17 UTC] Smile Please, life is beautiful.

The following is documentation about both wp_debug () and wp_debug_queries ()

 

wp_debug ()

wp_debug () outputs debug messages to either the screen or the debug log

Description

wp_debug ( mixed $expression )

wp_debug () displays information about a variable to either the screen or the debug log, depending on WP Debug settings in the admin dashboard.

Parameters

expression

The expression to be displayed. It can be either be an integer, a float, a string, an array, or an object.

Return Values

This function does not return any value.

Examples

Outputting a string

wp_debug (“Hello there”);

The above example will output:

[22-Sep-2015 07:59:27 UTC] Hello there

 

wp_debug_queries ()

wp_debug_queries () saves the database queries to an array and that array can be displayed to help analyze those queries. To be able to use this function, you must set the SAVEQUERIES named constant to true via the settings page of WP Debug; this causes each query to be saved, along with the time it took to execute, and the function that called it.

Parameters

This function does not take any parameters.

Return Values

This function does not return any value.