Show error notice in admin when debugging is enabled

A lot of users, including developers, forget to disable WP_DEBUG after they finish troubleshooting. A simple error notice in admin would be a helpful reminder that debugging is enabled. We do that for all of our hosting customers. It’s very helpful, reminds me to disable it frequently.

I’ve seen debug.log files in GBs in size because people forget to disable it for years.

Read-only archive:

Author: Viktor Nagornyy

Vote count: 12

Status: open


My idea, still want it :slight_smile:


Yes, agree. I currently have this added to the “At a Glance” widget but the warning could go anywhere.


I’ve also added the debugging status to my “Site Overview” widget (or whatever I ended up deciding to call it) to replace the At a Glance widget. In some cases, I’ve colored the admin menu bar to a bright red when debugging was enabled, so, there was little chance of ever missing it.


As I often do, I’ll post an “…in the meantime…” so…

In the meantime, here’s a quick function that will put the debugging status into the admin bar. Just copy the code into a utility plugin.

I think this method is preferable to using an admin notice as requested in the petition because 1) admin notices are limited in where they can be displayed, 2) the admin bar is always front-and-center, 3) this method shows the status on both front and back end admin bars.

The Result

When debugging is enabled.

When debugging is disabled.

The Code


function codepotent_debug_notifier_register_admin_bar() {

	// ...adjust the permission to suit your needs.
	if (!current_user_can('manage_options')) {

	// Bring the admin bar into scope.
	global $wp_admin_bar;

	// Assume debugging is disabled; set an appropriate text label.
	$label = esc_html__('Debugging Disabled', 'codepotent-debug-notifier');

	// Check if debugging is actually enabled; if so, reset the label.
	if (defined('WP_DEBUG')) {
		if (WP_DEBUG == true) { // Loose comparison is intentional here.
			$label = '<div style="color:#f00;">'.esc_html__('Debugging Enabled', 'codepotent-debug-notifier').'</div>';

	// Add the admin bar entry.
		'parent' => false,
		'id'     => 'codepotent-debug-notifier',
		'title'  => $label

add_action('wp_before_admin_bar_render', 'codepotent_debug_notifier_register_admin_bar');

I’m not sure if there’s a size limit for entries in the snippet directory, but, the function I added above may be a good candidate for it.


I was thinking the same thing. Don’t see why size should matter. I’m very enthusiastic about the snippet repo. I think a lot of the petition suggestions will end up in there.


This petition will be closed, but you can monitor progress on GitHub:

This topic was automatically closed after 3 days. New replies are no longer allowed.