Did you know that WordPress provides several debugging tools for you? These are especially useful for theme and plugin developers. We can also find some plugins which can help debug 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 a 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:
[php]define(‘WP_DEBUG’, true);[/php]
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]
SAVE_QUERIES
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).
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:
[php]define( ‘SCRIPT_DEBUG’, true );[/php]
WP Crontrol
WP Crontrol is a WordPress plugin designed to give you detailed control over your website’s WP-Cron system. It allows you to view, edit, add, and manage cron events and schedules, providing insights into scheduled tasks and their execution.
The plugin supports timezone awareness, alerts for misfiring events, and offers a privacy-focused approach, ensuring no data is sent to third parties. WP Crontrol is a valuable tool for developers and website administrators seeking to optimize and debug scheduled tasks within WordPressββ.
Activity Log
The Activity Log plugin for WordPress is a comprehensive solution for monitoring and tracking all activities on your WordPress site. It acts like a black box, recording every action in the WordPress admin area, allowing you to see what users are doing on your site in an activity log.
This plugin is especially useful for identifying unauthorized activities, tracking post publications, and monitoring plugin/theme changes. It’s designed to operate efficiently without affecting site performance and supports GDPR compliance by providing tools for data export and erasure.
Ideal for website administrators looking to secure their site and maintain an audit trail of user actionsββ.
Do you use any other tools? Let us know!
One Response
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.