Warn When Debug Display Is On in Production
Alerts administrators when WP_DEBUG shows errors on screen on a production site, where visitors could see file paths and warnings.
Opens WPIDE on
Code
add_action( 'admin_notices', function () {
if ( ! current_user_can( 'manage_options' ) || 'production' !== wp_get_environment_type() ) {
return;
}
$displaying = defined( 'WP_DEBUG' ) && WP_DEBUG && ( ! defined( 'WP_DEBUG_DISPLAY' ) || WP_DEBUG_DISPLAY );
if ( $displaying ) {
echo '<div class="notice notice-warning"><p><strong>Debug output is visible.</strong> WP_DEBUG is on and errors are displayed on this production site. Set WP_DEBUG_DISPLAY to false in wp-config.php.</p></div>';
}
} );
Notes
The environment type comes from WP_ENVIRONMENT_TYPE and defaults to production.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.