debug-bar.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. jQuery(function($) {
  2. function runAjaxAction(button, action) {
  3. button = $(button);
  4. var panel = button.closest('.puc-debug-bar-panel-v5');
  5. var responseBox = button.closest('td').find('.puc-ajax-response');
  6. responseBox.text('Processing...').show();
  7. $.post(
  8. ajaxurl,
  9. {
  10. action : action,
  11. uid : panel.data('uid'),
  12. _wpnonce: panel.data('nonce')
  13. },
  14. function(data) {
  15. //The response contains HTML that should already be escaped in server-side code.
  16. //phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
  17. responseBox.html(data);
  18. },
  19. 'html'
  20. );
  21. }
  22. $('.puc-debug-bar-panel-v5 input[name="puc-check-now-button"]').on('click', function() {
  23. runAjaxAction(this, 'puc_v5_debug_check_now');
  24. return false;
  25. });
  26. $('.puc-debug-bar-panel-v5 input[name="puc-request-info-button"]').on('click', function() {
  27. runAjaxAction(this, 'puc_v5_debug_request_info');
  28. return false;
  29. });
  30. // Debug Bar uses the panel class name as part of its link and container IDs. This means we can
  31. // end up with multiple identical IDs if more than one plugin uses the update checker library.
  32. // Fix it by replacing the class name with the plugin slug.
  33. var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v5');
  34. panels.each(function() {
  35. var panel = $(this);
  36. var uid = panel.data('uid');
  37. var target = panel.closest('.debug-menu-target');
  38. //Change the panel wrapper ID.
  39. target.attr('id', 'debug-menu-target-puc-' + uid);
  40. //Change the menu link ID as well and point it at the new target ID.
  41. $('#debug-bar-menu').find('.puc-debug-menu-link-' + uid)
  42. .closest('.debug-menu-link')
  43. .attr('id', 'debug-menu-link-puc-' + uid)
  44. .attr('href', '#' + target.attr('id'));
  45. });
  46. });