class-debug-bar-php.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. class Debug_Bar_PHP extends Debug_Bar_Panel {
  3. var $warnings = array();
  4. var $notices = array();
  5. var $real_error_handler = array();
  6. function init() {
  7. if ( ! WP_DEBUG )
  8. return false;
  9. $this->title( __('Notices / Warnings', 'debug-bar') );
  10. $this->real_error_handler = set_error_handler( array( &$this, 'error_handler' ) );
  11. }
  12. function is_visible() {
  13. return count( $this->notices ) || count( $this->warnings );
  14. }
  15. function debug_bar_classes( $classes ) {
  16. if ( count( $this->warnings ) )
  17. $classes[] = 'debug-bar-php-warning-summary';
  18. elseif ( count( $this->notices ) )
  19. $classes[] = 'debug-bar-php-notice-summary';
  20. return $classes;
  21. }
  22. function error_handler( $type, $message, $file, $line ) {
  23. $_key = md5( $file . ':' . $line . ':' . $message );
  24. switch ( $type ) {
  25. case E_WARNING :
  26. case E_USER_WARNING :
  27. $this->warnings[$_key] = array( $file.':'.$line, $message, wp_debug_backtrace_summary( __CLASS__ ) );
  28. break;
  29. case E_NOTICE :
  30. case E_USER_NOTICE :
  31. $this->notices[$_key] = array( $file.':'.$line, $message, wp_debug_backtrace_summary( __CLASS__ ) );
  32. break;
  33. case E_STRICT :
  34. // TODO
  35. break;
  36. case E_DEPRECATED :
  37. case E_USER_DEPRECATED :
  38. // TODO
  39. break;
  40. case 0 :
  41. // TODO
  42. break;
  43. }
  44. if ( null != $this->real_error_handler )
  45. return call_user_func( $this->real_error_handler, $type, $message, $file, $line );
  46. else
  47. return false;
  48. }
  49. function render() {
  50. echo "<div id='debug-bar-php'>";
  51. echo '<h2><span>Total Warnings:</span>' . number_format( count( $this->warnings ) ) . "</h2>\n";
  52. echo '<h2><span>Total Notices:</span>' . number_format( count( $this->notices ) ) . "</h2>\n";
  53. if ( count( $this->warnings ) ) {
  54. echo '<ol class="debug-bar-php-list">';
  55. foreach ( $this->warnings as $location_message_stack ) {
  56. list( $location, $message, $stack) = $location_message_stack;
  57. echo '<li class="debug-bar-php-warning">WARNING: ';
  58. echo str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message);
  59. echo '<br/>';
  60. echo $stack;
  61. echo '</li>';
  62. }
  63. echo '</ol>';
  64. }
  65. if ( count( $this->notices ) ) {
  66. echo '<ol class="debug-bar-php-list">';
  67. foreach ( $this->notices as $location_message_stack) {
  68. list( $location, $message, $stack) = $location_message_stack;
  69. echo '<li class="debug-bar-php-notice">NOTICE: ';
  70. echo str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message);
  71. echo '<br/>';
  72. echo $stack;
  73. echo '</li>';
  74. }
  75. echo '</ol>';
  76. }
  77. echo "</div>";
  78. }
  79. }