Skip to content

Instantly share code, notes, and snippets.

@johnalarcon
Created August 31, 2021 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnalarcon/fdc5d061466f5d0578face2d58a01878 to your computer and use it in GitHub Desktop.
Save johnalarcon/fdc5d061466f5d0578face2d58a01878 to your computer and use it in GitHub Desktop.
Display debugging state (enabled/disabled) in the ClassicPress admin bar
function codepotent_debug_notifier_register_admin_bar() {
// ...adjust the permission to suit your needs.
if (!current_user_can('manage_options')) {
return;
}
// 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.
$wp_admin_bar->add_menu([
'parent' => false,
'id' => 'codepotent-debug-notifier',
'title' => $label
]);
}
add_action('wp_before_admin_bar_render', 'codepotent_debug_notifier_register_admin_bar');
// Related discussion: https://forums.classicpress.net/t/show-error-notice-in-admin-when-debugging-is-enabled/2921
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment