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 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:
[php]if (!defined(‘WP_DEBUG’)) define(‘WP_DEBUG’, true);[/php]
The WordPress database class can be told to store query history:
[php]define( ‘SAVEQUERIES’, true );[/php]
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).
[php]define( ‘SCRIPT_DEBUG’, true );[/php]
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 lets you take control over what’s happening in the WP-Cron system.
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:
- Memory usage
- Operating System
- WordPress Version
- 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
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.
This Plugin integrates FirePHP in your WordPress installation and simplifies developing. No more
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.
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.
- 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.
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.
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.
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.
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)
Do you use any other tools? Let us know!