From 5a3c214836a1ea22b0fe698c49a18ae70e75ea7b Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Sat, 27 Oct 2012 12:26:24 +0000 Subject: [PATCH] Fix duplicate IDs in the Debug Bar. When multiple instances of the update checker are active at the same time, each will have its own PluginUpdateCheckerPanel instance and its own entry in the Debug Bar. However, since all instances have the same class name, and Debug Bar uses this name to generate link and wrapper IDs, we will end up with duplicate IDs and a semi-broken debug bar. I've added a bit of JS that will find update checker panels and replace the relevant IDs with new ones based on the plugin slug, not class. --- debug-bar-panel.php | 6 +++++- js/debug-bar.js | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/debug-bar-panel.php b/debug-bar-panel.php index 54b7b79..7f6c629 100644 --- a/debug-bar-panel.php +++ b/debug-bar-panel.php @@ -11,7 +11,11 @@ class PluginUpdateCheckerPanel extends Debug_Bar_Panel { public function __construct($updateChecker) { $this->updateChecker = $updateChecker; - $title = sprintf('PUC (%s)', $this->updateChecker->slug); + $title = sprintf( + 'PUC (%s)', + esc_attr($this->updateChecker->slug), + $this->updateChecker->slug + ); parent::Debug_Bar_Panel($title); } diff --git a/js/debug-bar.js b/js/debug-bar.js index 7795a6a..1efd941 100644 --- a/js/debug-bar.js +++ b/js/debug-bar.js @@ -29,4 +29,24 @@ jQuery(function($) { runAjaxAction(this, 'puc_debug_request_info'); return false; }); + + + // Debug Bar uses the panel class name as part of its link and container IDs. This means we can + // end up with multiple identical IDs if more than one plugin uses the update checker library. + // Fix it by replacing the class name with the plugin slug. + var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel'); + panels.each(function(index) { + var panel = $(this); + var slug = panel.data('slug'); + var target = panel.closest('.debug-menu-target'); + + //Change the panel wrapper ID. + target.attr('id', 'debug-menu-target-' + slug); + + //Change the menu link ID as well and point it at the new target ID. + $('#puc-debug-menu-link-' + panel.data('slug')) + .closest('.debug-menu-link') + .attr('id', 'debug-menu-link-' + slug) + .attr('href', '#' + target.attr('id')); + }); }); \ No newline at end of file