Recently I was talking to another developer about how to detect WP_DEBUG
being set on a WordPress installation.
Here is the code I use.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
// WP_DEBUG is set to a truthy value (e.g. true).
}
WP_DEBUG
WP_DEBUG is a constant used in WordPress to put the site into “debug” mode. The idea here is when figuring out a problem (i.e. debugging), additional information is helpful.
Three Possible States of WP_DEBUG
While we are interested in whether WP_DEBUG
is a truthy or a falsey value, there is a third possible state. WP_DEBUG can be undefined. This is why our conditional has two checks:
- Is
WP_DEBUG
defined?defined( 'WP_DEBUG' )
- If
WP_DEBUG
is defined, is it a truthy value
Leave a Reply