This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

My Whatever Debug Tracer (Wordpress Plugin)

By: kitchin on May 27th, 2012  |  syntax: PHP  |  size: 1.89 KB  |  views: 142  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: My Whatever Debug Tracer
  4. Description: In WP_DEBUG mode, find out what plugin or theme file is causing notices.
  5. */
  6.  
  7. ////////////////////////////////////////////////////////
  8. // You can upload this file as wp-content/mu-plugins/my-whatever-debug-tracer.php
  9. // and it will automatically activate (see http://codex.wordpress.org/Must_Use_Plugins ),
  10. // or put it in your theme's functions.php, or use it as a normal plugin.
  11. ////////////////////////////////////////////////////////
  12.  
  13.  
  14. if (WP_DEBUG) {
  15.   // Set WP_DEBUG true in wp-config.php, otherwise this plugin does nothing.
  16.  
  17.   // Note, WP_DEBUG can be set like this in wp-config.php, for testing a live site:
  18.   //    define('WP_DEBUG', 'your ip number' === @$_SERVER['REMOTE_ADDR']);
  19.  
  20.   add_action( 'deprecated_argument_run', 'my_whatever_debug_backtrace' );
  21.   add_action( 'doing_it_wrong_run', 'my_whatever_debug_backtrace' );
  22. }
  23.  
  24.  
  25. if (! function_exists('function my_whatever_debug_backtrace')) {
  26. ///////////////////////////////////////////////////////
  27. function my_whatever_debug_backtrace($f) {
  28.  
  29.   // Another way to do it, suggested by
  30.   // http://wordpress.org/support/topic/notice-wp_deregister_script-was-called-incorrectly
  31.   // would be:
  32.   //    throw new Exception("Testing");
  33.   // (It will halt the script).
  34.  
  35.   // Just print the trace for the first offender, to make the output easier to read.
  36.   if (defined('MY_WHATEVER_DEBUG_DONE')) return;
  37.   define('MY_WHATEVER_DEBUG_DONE', true);
  38.  
  39.   printf("<pre>my_whatever_debug_backtrace($f)</pre>\n");
  40.   $fvs= debug_backtrace();
  41.   foreach ($fvs as $i=>$fv) {
  42.         // Just print the first line, and the first line referencing wp-content
  43.         $m= is_int(strpos((string)@$fv['file'], 'wp-content'));
  44.         if ($i==0 || $m) {
  45.                 printf(
  46.                         "<pre>my_whatever_debug_backtrace(%s)[%d]=[%s]</pre>\n",
  47.                         $f,
  48.                         $i,
  49.                         htmlspecialchars(print_r($fv,1))
  50.                 );
  51.                 if ($m) break;
  52.         }
  53.   }
  54. }
  55. }
  56.  
  57. ?>
clone this paste RAW Paste Data