I am trying to create a debugging mode in one of my plugins so users can easily enable WP_DEBUG on their own, and hopefully report back to us with helpful error messages. Right now we ask them to modify their wp-config.php, but that's beyond some users' capabilities. I was hoping to just add define( 'WP_DEBUG', true );in our plugin if the user has checked that option, but it appears you can only enable WP_DEBUG from the wp-config.php file.

Does anyone know of any way to enable WP_DEBUG from anywhere else but wp-config? Or is there another useful WP function that I could be using instead?

Thanks, Dalton

  • Guess what, I tried the exact same thing a couple of days back, but didn't work. And if there was a way, then an option to turn on/off the debug mode via the dashboard would've been there cause editing the config is very risky! Anyways you can try this way: wordpressluv.com/… – Rutwick Gangurde Mar 28 '12 at 12:12
  • Thanks Rutwick, that link is super helpful. Won't work for me in this case (I need to be able to display errors without editing wp-config.php) but I can see this coming in very handy. – Dalton Mar 28 '12 at 13:52
  • You're welcome @Dalton! If you find a way, please let me know too! – Rutwick Gangurde Mar 28 '12 at 14:30

WordPress logic forces WP_DEBUG to be defined to something, even if it's omitted it will be set to false in wp_initial_constants() during load.

However "background" (that is not when it is checked explicitly) function of WP_DEBUG is to be a flag for how PHP error reporting should be configured on runtime. That configuration is performed by wp_debug_mode() and at any point after that can be changed by your plugin's code if necessary.

  • Thanks for that background info, I did not know about wp_debug_mode(). Even when changed after the fact, it still cannot override the initial setting of WP_DEBUG in the wp-config, can it? – Dalton Mar 28 '12 at 13:51
  • @Dalton correct, you can't change constant itself, but you can easily change error reporting settings. – Rarst Mar 28 '12 at 14:06

It is not possible to turn on WP_DEBUG because it's defined in wp-config.php by default, redefinition of defined constants is not possible in PHP.

If you want to keep them out of wp-config.php ask them to add to the top something like:

if ( file_exists( 'safe-wp-config.php' ) ) {
    /* this will contains WP_DEBUG */
    include 'safe-wp-config.php';


WP_DEBUG is assumed to be false when missing, so let them remove WP_DEBUG completely from wp-config.php and use wherever/whenever they like.

  • 2
    it's possible with runkit – onetrickpony Mar 28 '12 at 13:27
  • @onetrickpony Thanks for the tip but I need some advice. Why wouldn't something along these lines work (added in my theme's functions.php)? runkit_constant_redefine( 'WP_DEBUG' , true ); runkit_constant_add( 'WP_DEBUG_LOG', true ); runkit_constant_add( 'WP_DEBUG_DISPLAY', true ); – Henrik Mar 26 '14 at 16:26

However, if you really want to display errors and not store them in log file (like I wanted), then you can turn on debugging for your Public IP like following -

if ( $_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx')
define('WP_DEBUG', true);

There should not be a problem as long as you are on Static IP, but if you have dynamic IP, you probably can change the IP every time you need to turn on debugigng.


I am very late to the party. However, I had a requirement where I had to enable wp_debug and I had no access to the files. This plugin helped: https://wordpress.org/plugins/debug/

Maybe you can do the same thing as the plugin? Edit wp-config.php programmatically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.