As a WordPress theme or plugin development company, it is highly recommended that the developers must debug their code while working on it. Since they plan to release their products publicly, Debugging PHP code is part of any project. Thankfully WordPress comes with specific debug systems designed to simplify the debugging process as well as standardize code across the core, plugins and themes. so here we gonna discuss how we can start debug and increase our quality of code.
It is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It is assumed to be false by default and is usually set to true in the wp-config.php file on development copies of WordPress.
Note: The true and false values in the example are boolean (true/false) values.
It is not recommended to use WP_DEBUG or the other debug tools on live sites; they are meant for local testing and staging installs.
Enabling WP_DEBUG will cause all PHP errors, notices and warnings to be displayed. This is likely to modify the default behavior of PHP which only displays fatal errors and/or shows a white screen of death when errors are reached.
Enabling WP_DEBUG will also cause notices about deprecated functions and arguments within WordPress that are being used on your site. Deprecation notices often indicate the new function that should be used instead.
It is a companion to WP_DEBUG that causes all errors to also be saved to a debug.log log file inside the /wp-content/ directory. This is useful if you want to review all notices later or need to view notices generated off-screen (e.g. during an AJAX request or wp-cron run).
It is another companion to WP_DEBUG that controls whether debug messages are shown inside the HTML of pages or not. The default is ‘true’ which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with WP_DEBUG_LOG so that errors can be reviewed later.
The SAVEQUERIES definition saves the database queries to an array and that array can be displayed to help analyze those queries. The constant defined as true causes each query to be saved, how long that query took to execute, and what function called it.
The array is stored in the global $wpdb->queries.
NOTE: This will have a performance impact on your site, so make sure to turn this off when you aren’t debugging.