Defining Constants

Debugging PHP code is part of any project, but WordPress comes with specific debug systems designed to simplify the process as well as standardize code across the core, plugins, and themes

When developing a WordPress site, on your local or development environment, its imperative to have the debug log turned on, in order to catch any errors/warnings before shipping the code further. Its quite easy to do, by simply setting these constants in wp-config.php:

define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );   // WP 5.2 and later
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
define( 'SCRIPT_DEBUG', true );

NOTE: You must insert this BEFORE /* That’s all, stop editing! Happy blogging. */ in the wp-config.php file.

The purpose of this is to

  1. Disable WordPress Fatal Error Handler. When a fatal error occurs, the fatal error handler shows visitors a message informing them that the site is experiencing technical difficulties.
  2. Route the error logging information to wp-content/debug.log so that you can tail it locally and be aware of any error or warning that occurs when running the site.
  3. Enlist any or all deprecated functions or arguments being used whenever they are called to ensure that your code will continue to work as intended in the long run.
  4. Disable the sending of error log statements in the response so that you can ensure that no Ajax functionality breaks because of such statements.
  5. Use the development versions of core CSS and JS files rather than the minified versions that are normally loaded.

To learn more about these constants (and a few more) that we can define in wp-config.php please refer WordPress Codex page for debugging.