class-debug-bar-php.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 );
  28. break;
  29. case E_NOTICE :
  30. case E_USER_NOTICE :
  31. $this->notices[$_key] = array( $file.':'.$line, $message );
  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) {
  56. list( $location, $message) = $location_message;
  57. echo "<li class='debug-bar-php-warning'>WARNING: ".str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message). "</li>";
  58. }
  59. echo '</ol>';
  60. }
  61. if ( count( $this->notices ) ) {
  62. echo '<ol class="debug-bar-php-list">';
  63. foreach ( $this->notices as $location_message) {
  64. list( $location, $message) = $location_message;
  65. echo "<li class='debug-bar-php-notice'>NOTICE: ".str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message). "</li>";
  66. }
  67. echo '</ol>';
  68. }
  69. echo "</div>";
  70. }
  71. }