WordPress Debugging Guide

Did you know that WordPress provides a number of debugging tools for you? These are especially useful for theme and plugin developers. We can also find some plugins which can be helpful in debugging our WordPress code. If you’re interested in monitoring tools please take a look at our review of WordPress monitoring plugins.

Let’s take a look at what WordPress provides as standard first.

In-Built WordPress Debugging Features

The features below are all built into the WordPress standard installation and can be easily activated when needed.

WP_DEBUG

WP_DEBUG is a WP constant that is found in the wp-config.php file. Once you define it in wp-config.php you’ll start seeing PHP notices and also WordPress-generated debug messages, particularly deprecated function usage. To activate this feature, open the wp-config.php file and enter the following at the end of the file:

There’s also WP_DEBUG_DISPLAY and WP_DEBUG_LOG, which enable you to log notices generated by WP_DEBUG to a wp-content/debug.log file.

WP_DEBUG should not be used on a live site.

WP_DEBUG will often reveal potential problems in your code, such as unchecked indexes (empty() and isset() are your friend) and undefined variables. (You may even find problems in WordPress itself, in which case you should file a bug report.)

You can also put the following code into your theme’s functions.php file to enable WP_DEBUG:

SAVE_QUERIES

The WordPress database class can be told to store query history:

When this is defined, $wpdb->queries stores an array of queries that were executed, along with the time it takes to execute them.
The database class has additional error and debugging tools, which are documented on the Codex (though when in doubt, check the source).

SCRIPT_DEBUG

In the admin, WordPress minimizes and concatenates JavaScript and CSS. But WP also comes with the “development” scripts, in the form of dev.js and dev.css. To use these instead:

Plugins

WordPress offers some excellent plugins which are aimed at developers more than normal users, and can be of tremendous help for debugging and optimising code.

WP-Crontrol

WP-Crontrol lets you take control over what’s happening in the WP-Cron system.

http://wordpress.org/extend/plugins/wp-crontrol/

Debug Objects

The Plugin Debug Objects provides the user, which has the appropriate rights, normally the administrator, a large number of information. Values and content get displayed at the frontend of the blog, to analyze errors but also to better understand WordPress.

The Plugin provides in various tabs information to:

  • PHP
  • Memory usage
  • Operating System
  • Server
  • WordPress Version
  • Language
  • Very extensive definitions of various constants
  • Cookie definitions
  • File Permissions
  • Separate user and usermeta tables
  • FTP and SSH definitions
  • Query information
  • Conditional tags; value of the tag
  • Theme information
  • Template Information
  • Cache content
  • Hooks and filters
  • Functions, which respond on hooks and filters
  • Contents of arrays to hooks and filters
  • All defined constants

http://wordpress.org/extend/plugins/debug-objects/

Black Box

The BlackBox plugin adds a thin black bar to the top of any WordPress post or page, and provides quick access to errors, global variables, profile data, and SQL queries.

http://wordpress.org/extend/plugins/blackbox-debug-bar/

WP-FirePHP

This Plugin integrates FirePHP in your WordPress installation and simplifies developing. No more  vardump() and  echo while debugging. FirePHP take care of it, clean and easy. WP-FirePHP simplifies this process, since it integrates FirePHP and provide diverse standards of PHP and WordPress. Including all constants, global variables and PHP standard global variables. Works only under PHP 5.

http://wordpress.org/extend/plugins/wp-firephp/

WP Developer Assistant

WP Developer Assistant is a WordPress plugin developed by a WordPress developer for WordPress developers.

  • Have you ever needed to run a query when you didn’t have access to phpMyAdmin or SSH?
  • Don’t you hate it when you need to upload a plugin, theme, or other file and don’t have FTP access?
  • Have you ever wondered where that action or filter hook gets called?
  • Want to enable errors while hiding them from everyone else?
  • Wouldn’t it be great if you could output a full listing of PHP global variable values on each page so debugging would be easier?
  • Ever wanted to modify one of those serialized options?
  • Would you like to quickly see a full list of defined constants?

It’s thoughts like these that caused me to make this plugin. WP Developer Assistant is the first WordPress plugin of its kind. It essentially is a toolkit that makes life as a WordPress developer easier.

Features

  • Customizable enabling of PHP errors that only show for your user.
  • Display values of PHP’s built-in global variables (_POST, _REQUEST, _FILE, _ENV, etc) on each page.
  • Easily modify Options table values, including serialized data.
  • View a full list of all the add_action, do_action, add_filter, and apply_filters function calls complete with information on function names, priorities, number of accepted arguments, source file name, and file line number.
  • Quickly execute queries with the Run Query tool.
  • Show phpinfo().
  • View a comprehensive list of all the defined named constants, their current value, the declared value, the source file name of the definition, and the file line number of the definition.
  • Quickly and easily upload files to any place inside your WordPress installation. The uploader will even automatically extract archives to the destination directory.

http://wordpress.org/extend/plugins/wp-developer-assistant/

Core Control

Core Control is mainly a Developers plugin, However it can be used by end users alike, Just realise, That novice users are not the initial target audience, and as such, this plugin (and its modules) may be more technical aimed.

Core Control is only supported on WordPress 2.9+, Due to this being aimed at debugging and developers, Only the latest stable release will be supported. It may work in older versions, but this is untested.

Core Control is a set of plugin modules which can be used to control certain aspects of the WordPress control. Currently, Core Control features modules for managing Filesystem Access, Managing plugin/theme/core updates, Managing HTTP Transports & External HTTP Request logging.

http://wordpress.org/extend/plugins/core-control/

Cron View

This plugin lets you view the next cron jobs that are scheduled to run on your site. Very useful when debugging your site especially for plugins that rely on Cron, such as BackupBuddy.

http://wordpress.org/extend/plugins/cron-view/installation/

P3 (Plugin Performance Profiler) 

This plugin creates a profile of your WordPress site’s plugins’ performance by measuring their impact on your site’s load time.  Often times, WordPress sites load slowly because of poorly configured plugins or because there are so many of them. By using the P3 plugin, you can narrow down anything causing slowness on your site.

http://wordpress.org/extend/plugins/p3-profiler/

WP Log Viewer

Add widget into Dashboard for view the day errors, view full log in page this plugin, configure the wp-config.php (optional) and add link to view errors in admin bar (optional)

http://wordpress.org/plugins/wp-viewer-log

Do you use any other tools? Let us know!

About Jean Galea

Jean Galea is a WordPress developer, entrepreneur and padel player. He is the founder of WP Mayor, the plugins WP RSS Aggregator and EDD Bookings, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Related Articles

  • WordPress System Monitoring Plugins

    How do we know that our WordPress system is running well and there are no problems vis-a-vis the hosting account? Two plugins can help out in this task, let's take…

  • A forum on your website can increase visitor engagement and allow you to start a loyal community. There are a few WordPress forum plugins available. Let's take a look at…

  • A number of plugins are sprouting up, and their sole purpose is to hide the fact that you use WordPress. What's the reason for doing that? The number one reason…

One Response

  1. Shirley, Bar Native
    Shirley, Bar Native March 18, 2014 at 18:55 | | Reply

    Useful development tools. I especially like the Debug Objects. Black Box used to be my favorite, but I don’t like that debug messages are shown to non-admin users.

Leave a Reply