class-debug-bar-deprecated.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // Alot of this code is massaged from Andrew Nacin's log-deprecated-notices plugin
  3. class Debug_Bar_Deprecated extends Debug_Bar_Panel {
  4. var $deprecated_functions = array();
  5. var $deprecated_files = array();
  6. var $deprecated_arguments = array();
  7. function init() {
  8. $this->title( __('Deprecated', 'debug-bar') );
  9. add_action( 'deprecated_function_run', array( &$this, 'deprecated_function_run' ), 10, 3 );
  10. add_action( 'deprecated_file_included', array( &$this, 'deprecated_file_included' ), 10, 4 );
  11. add_action( 'deprecated_argument_run', array( &$this, 'deprecated_argument_run' ), 10, 3 );
  12. // Silence E_NOTICE for deprecated usage.
  13. foreach ( array( 'function', 'file', 'argument' ) as $item )
  14. add_filter( "deprecated_{$item}_trigger_error", '__return_false' );
  15. }
  16. function prerender() {
  17. $this->set_visible(
  18. count( $this->deprecated_functions )
  19. || count( $this->deprecated_files )
  20. || count( $this->deprecated_arguments )
  21. );
  22. }
  23. function render() {
  24. echo "<div id='debug-bar-deprecated'>";
  25. echo '<h2><span>Total Functions:</span>' . number_format( count( $this->deprecated_functions ) ) . "</h2>\n";
  26. echo '<h2><span>Total Arguments:</span>' . number_format( count( $this->deprecated_arguments ) ) . "</h2>\n";
  27. echo '<h2><span>Total Files:</span>' . number_format( count( $this->deprecated_files ) ) . "</h2>\n";
  28. if ( count( $this->deprecated_functions ) ) {
  29. echo '<ol class="debug-bar-deprecated-list">';
  30. foreach ( $this->deprecated_functions as $location => $message)
  31. echo "<li class='debug-bar-deprecated-function'>".str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message). "</li>";
  32. echo '</ol>';
  33. }
  34. if ( count( $this->deprecated_files ) ) {
  35. echo '<ol class="debug-bar-deprecated-list">';
  36. foreach ( $this->deprecated_files as $location => $message)
  37. echo "<li class='debug-bar-deprecated-function'>".str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message). "</li>";
  38. echo '</ol>';
  39. }
  40. if ( count( $this->deprecated_arguments ) ) {
  41. echo '<ol class="debug-bar-deprecated-list">';
  42. foreach ( $this->deprecated_arguments as $location => $message)
  43. echo "<li class='debug-bar-deprecated-function'>".str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message). "</li>";
  44. echo '</ol>';
  45. }
  46. echo "</div>";
  47. }
  48. function deprecated_function_run($function, $replacement, $version) {
  49. $backtrace = debug_backtrace();
  50. $bt = 4;
  51. // Check if we're a hook callback.
  52. if ( ! isset( $backtrace[4]['file'] ) && 'call_user_func_array' == $backtrace[5]['function'] ) {
  53. $bt = 6;
  54. }
  55. $file = $backtrace[ $bt ]['file'];
  56. $line = $backtrace[ $bt ]['line'];
  57. if ( ! is_null($replacement) )
  58. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'debug-bar'), $function, $version, $replacement );
  59. else
  60. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', 'debug-bar'), $function, $version );
  61. $this->deprecated_functions[$file.':'.$line] = $message;
  62. }
  63. function deprecated_file_included( $old_file, $replacement, $version, $message ) {
  64. $backtrace = debug_backtrace();
  65. $file = $backtrace[4]['file'];
  66. $file_abs = str_replace(ABSPATH, '', $file);
  67. $line = $backtrace[4]['line'];
  68. $message = empty( $message ) ? '' : ' ' . $message;
  69. if ( ! is_null( $replacement ) )
  70. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'debug-bar'), $file_abs, $version, $replacement ) . $message;
  71. else
  72. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', 'debug-bar'), $file_abs, $version ) . $message;
  73. $this->deprecated_files[$file.':'.$line] = $message;
  74. }
  75. function deprecated_argument_run( $function, $message, $version) {
  76. $backtrace = debug_backtrace();
  77. $bt = 4;
  78. if ( ! isset( $backtrace[4]['file'] ) && 'call_user_func_array' == $backtrace[5]['function'] ) {
  79. $bt = 6;
  80. }
  81. $file = $backtrace[ $bt ]['file'];
  82. $line = $backtrace[ $bt ]['line'];
  83. $this->deprecated_arguments[$file.':'.$line] = $message;
  84. }
  85. }