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.
This commit is contained in:
parent
8260c0e712
commit
5a3c214836
|
|
@ -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(
|
||||
'<span id="puc-debug-menu-link-%s">PUC (%s)</span>',
|
||||
esc_attr($this->updateChecker->slug),
|
||||
$this->updateChecker->slug
|
||||
);
|
||||
parent::Debug_Bar_Panel($title);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue