Troubleshooting PHP code is a piece of any undertaking. For this, WordPress incorporates a few settings that you can use to help investigate the principle application, topics, your own particular custom code, and that’s only the tip of the iceberg.
Some of the settings are specifically designed to use by developers and should not be used on “live” sites. Those settings include specific debug systems designed to simplify the process as well as standardize code across the core, plugins, and themes.
You can use them in certain scenarios to help troubleshoot errors you may be experiencing with third-party code, such as plugins or themes.
In this guide, I will tell you about various debugging tools and how you could efficiently perform WordPress debug task. I’m sure, it will increase the overall quality and interoperability of your code.
To do so, you initially need to enable debugging mode in WordPress:
- Log in to cPanel, or access your account using SFTP.
- Using the cPanel File Manager or the SFTP, open the wp-config.php file in your preferred text editor.
- Add the following line to the wp-config.php file:
define('WP_DEBUG', true); // Enable WP_DEBUG mode
- Save your changes and exit the text editor. If you choose SFTP then make sure you upload the updated wp-config.php file. Debugging mode is now active.
Enabling WP-DEBUG will cause all PHP errors, warnings and notices to be shown. This is probably going to alter the default conduct of PHP which just shows deadly mistakes as well as demonstrates a white screen of death when blunders are come to.
Such instance even leads to error messages for things that don’t seem broken but do not follow proper data validation conventions inside PHP.
Don’t get panic. They are easy to fix once you identified the relevant code and the resultant code will be bugless and easier to maintain.
Empowering WP_DEBUG will likewise cause notices about deprecated functions and arguments inside WordPress that are being utilized on your site. These are capacities or capacity contentions that have not been expelled from the center code yet but rather are slated for cancellation soon.
Though, there are also additional settings available in WordPress that will help you in your debugging task. Here is the list of them:
Let me explain them in detail,
WP_DEBUG_LOG is a partner to WP_DEBUG that makes all mistakes additionally be spared to a debug.log log record inside the/wp-content/. This is valuable on the off chance that you need to audit all notification later or need to see created off-screen.
Include the following line of code in your
define( 'WP_DEBUG_LOG', true ); // Enable Debug logging to the /wp-content/debug.log file
This will enable you to write to
/wp-content/debug.log using PHP’s built-in error_log() function, which can be useful for instance when debugging AJAX events.
WP_DEBUG_DISPLAY is another option that controls whether troubleshoot messages are appeared inside the HTML pages or not. The default is ‘genuine’ which demonstrates blunders and notices as they are produced. Setting this to false will conceal all mistakes. This ought to be utilized as a part of conjunction with WP_DEBUG_LOG so mistakes can be surveyed later.
for this, you need to incorporate following line of code to wp-config.php.
define( 'WP_DEBUG_DISPLAY', false ); // Disable display of errors and warnings
Add this piece of code to the same file as above:
define( 'SCRIPT_DEBUG', true ); // Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
The SAVEQUERIES is used as the definition that saves the database inquiries to a cluster and that exhibit can be shown to help examine those queries. The consistent characterized as true cases that make each query to be saved, to what extent that query executes, and what function called it.
define( 'SAVEQUERIES', true );
The array is stored in the global $wpdb->queries.
NOTE: This could impact on your site performance. Thus, ensure to turn this off when you aren’t debugging.
Hence, you are done. Now, stop editing.
You might also like my another article for Setting Up WordPress Error Logs using WP-Config.
In case, if you faced some issues during DEBUGGING, feel free to ask your question in the comment section below.