How to define WP_DEBUG as true outside of wp-config.php?

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

5 s
5

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.

Leave a Comment