class-debug-bar-deprecated.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_stack) {
  31. list( $message, $stack) = $message_stack;
  32. echo "<li class='debug-bar-deprecated-function'>";
  33. echo str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message);
  34. echo "<br/>";
  35. echo $stack;
  36. echo "</li>";
  37. }
  38. echo '</ol>';
  39. }
  40. if ( count( $this->deprecated_files ) ) {
  41. echo '<ol class="debug-bar-deprecated-list">';
  42. foreach ( $this->deprecated_files as $location => $message_stack) {
  43. list( $message, $stack) = $message_stack;
  44. echo "<li class='debug-bar-deprecated-file'>";
  45. echo str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message);
  46. echo "<br/>";
  47. echo $stack;
  48. echo "</li>";
  49. }
  50. echo '</ol>';
  51. }
  52. if ( count( $this->deprecated_arguments ) ) {
  53. echo '<ol class="debug-bar-deprecated-list">';
  54. foreach ( $this->deprecated_arguments as $location => $message_stack) {
  55. list( $message, $stack) = $message_stack;
  56. echo "<li class='debug-bar-deprecated-argument'>";
  57. echo str_replace(ABSPATH, '', $location) . ' - ' . strip_tags($message);
  58. echo "<br/>";
  59. echo $stack;
  60. echo "</li>";
  61. }
  62. echo '</ol>';
  63. }
  64. echo "</div>";
  65. }
  66. function deprecated_function_run($function, $replacement, $version) {
  67. $backtrace = debug_backtrace( false );
  68. $bt = 4;
  69. // Check if we're a hook callback.
  70. if ( ! isset( $backtrace[4]['file'] ) && 'call_user_func_array' == $backtrace[5]['function'] ) {
  71. $bt = 6;
  72. }
  73. $file = $backtrace[ $bt ]['file'];
  74. $line = $backtrace[ $bt ]['line'];
  75. if ( ! is_null($replacement) )
  76. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'debug-bar'), $function, $version, $replacement );
  77. else
  78. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', 'debug-bar'), $function, $version );
  79. $this->deprecated_functions[$file.':'.$line] = array( $message, wp_debug_backtrace_summary( null, $bt ) );
  80. }
  81. function deprecated_file_included( $old_file, $replacement, $version, $message ) {
  82. $backtrace = debug_backtrace( false );
  83. $file = $backtrace[4]['file'];
  84. $file_abs = str_replace(ABSPATH, '', $file);
  85. $line = $backtrace[4]['line'];
  86. $message = empty( $message ) ? '' : ' ' . $message;
  87. if ( ! is_null( $replacement ) )
  88. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'debug-bar'), $file_abs, $version, $replacement ) . $message;
  89. else
  90. $message = sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', 'debug-bar'), $file_abs, $version ) . $message;
  91. $this->deprecated_functions[$file.':'.$line] = array( $message, wp_debug_backtrace_summary( null, 4 ) );
  92. }
  93. function deprecated_argument_run( $function, $message, $version) {
  94. $backtrace = debug_backtrace( false );
  95. if ( $function === 'define()' ) {
  96. $this->deprecated_functions[] = array( $message, '' );
  97. return;
  98. }
  99. $bt = 4;
  100. if ( ! isset( $backtrace[4]['file'] ) && 'call_user_func_array' == $backtrace[5]['function'] ) {
  101. $bt = 6;
  102. }
  103. $file = $backtrace[ $bt ]['file'];
  104. $line = $backtrace[ $bt ]['line'];
  105. $this->deprecated_functions[$file.':'.$line] = array( $message, wp_debug_backtrace_summary( null, $bt ) );
  106. }
  107. }