I’m trying to disable WP_DEBUG_LOG if and only if debug.log exists. I’d like to hook into wp_footer and test if the file exists and if so disable my debug log. All I’ve found though is that WP_DEBUG_LOG is a constant and can only be changed from the wp-config.php file which is too early for my case. Is there a way to change it from a constant on install and keep it working as normal?
My only other thought is to create an option on install in the options table and just check it every time wp-config loaded to see if the value has changed but I was wanting to avoid that.
Granted I could check if the file exists before I define WP_DEBUG_LOG but somebody would have to view a page twice before debug log actually exists and is detected by the file_exists() (since it’s run very early) which is not optimal.
Does anybody know of a workaround to programmatically turn off WP_DEBUG_LOG?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
@Wyck was right, ( well sorta 😛 ) you can set error logs but
1) You need to enable debugging
2) ini_set('log_errors', 1); or 0 for false
3) You need to set a log location via ini_set('error_log, $location)
Once you have that set you can then if need be test if said file exists via $location and turn off log_errors by setting its value to 0.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0