Changeset 389439
- Timestamp:
- 05/26/2011 04:18:06 PM (15 years ago)
- Location:
- kb-debug/trunk
- Files:
-
- 1 added
- 3 edited
-
2.png (added)
-
README (modified) (5 diffs)
-
kb-debug.css (modified) (3 diffs)
-
kb_debug.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kb-debug/trunk/README
r389438 r389439 4 4 Requires at least: WordPress 3.0 5 5 Tested up to: 3.2 6 Stable tag: 0. 16 Stable tag: 0.2 7 7 8 8 Debug your plugins and themes. … … 10 10 == Description == 11 11 12 To log and show a list of all warnings, errors and notices generated by your plugin, add a ?KB_Debug_Errors to your URL. To see a list of all hooks in the order they fire as well as what arguments they are called with and what functions run on them (again, in which order), add a ?KB_Debug_Hooks to the URL. 12 * Call `kb_debug` with any arguments that you want to log and they will be pretty printed at the end of the document. 13 * To log and show a list of all warnings, errors and notices generated by your plugin, add `?KB_Debug_Errors` to your URL. 14 * To see a list of all hooks in the order they fire as well as what arguments they are called with and what functions run on them (again, in which order), 15 add a `?KB_Debug_Hooks` to the URL. 13 16 14 17 To see both just add ?KB_Debug_Errors&KB_Debug_Hooks. (Essentially $_GET[var] must be set to enable that feature). … … 16 19 17 20 == Installation == 18 19 21 Upload `kb_debug.php` and 'kb-debug.css' to the `/wp-content/mu-plugins/` directory. (Create this directory if it doesn't exist). 20 22 … … 31 33 == Screenshots == 32 34 1. Showing how errors and hooks appear on using this plugin. 35 2. Showing how debugging information is shown in the plugin. 33 36 34 37 == Changelog == … … 40 43 41 44 = 0.1 = 42 First version.45 * First version. -
kb-debug/trunk/kb-debug.css
r389435 r389439 12 12 13 13 .effect-border { 14 border-top: solid 1px #fff; 15 border-bottom: solid 1px #dfdfdf; 16 border-radius: 3px 3px 0 0; 17 padding: 10px; 18 } 19 20 #kb-debug { 21 background-color: #f0f0f0; 22 color: #111; 23 text-shadow: #fff 0 1px 0; 24 border-radius: 3px 3px 0 0; 25 border: solid 1px #ccc; 26 margin: 10px; 27 font-family: sans-serif; 28 font-size: 12px; 29 line-height: 20px; 30 } 31 32 #kb-debug .effect-border { 14 33 border-top: solid 1px #fff; 15 34 border-bottom: solid 1px #dfdfdf; … … 35 54 border-bottom: solid #dfdfdf 1px; 36 55 padding: 2px; 56 margin: 0; 37 57 } 38 58 … … 54 74 width: 95%; 55 75 overflow: auto; 76 padding: 10px; 77 margin: 10px; 56 78 } 57 79 -
kb-debug/trunk/kb_debug.php
r389436 r389439 46 46 47 47 /** 48 * The Base Class used to save errors and warnings information, if any. 48 * Used to save debugging information logged by the user. 49 */ 50 class KB_Debug { 51 52 /** 53 * Store any errors, notices, warnings or debug information. 54 * @access private 55 * @var Array 56 */ 57 private $logged; 58 59 /** 60 * Constructor. Initializes values and assigns actions. 61 */ 62 public function __construct() { 63 $this->logged = Array(); 64 65 add_action( 'shutdown', Array( &$this, 'display' ), 98 ); 66 wp_enqueue_style( 'kb-debug-css', KB_DEBUG_RELURL . "/kb-debug.css" ); 67 } 68 69 /** 70 * Display all logged debugging information. 71 * @access public 72 */ 73 function display() { 74 echo "<div class = 'kb-debug-box' id = 'kb-debug'><div class = 'effect-border'>"; 75 echo "<h2>Logged</h2>"; 76 echo "<ul>"; 77 foreach( $this->logged as $log ) { 78 echo "<li>"; 79 echo "<h3>{$log->backtrace['line']}, {$log->backtrace['file']}</h3>"; 80 foreach( $log->data as $data ) { 81 echo "<pre>"; print_r( $data ); echo "</pre>"; 82 } 83 echo "</li>"; 84 } 85 echo "</ul>"; 86 echo "</div></div>"; 87 } 88 89 /** 90 * Log array of arguments passed to it. Later pretty printed with a backtrace using print_r. 91 * Do not call this function directly. 92 * @access public 93 */ 94 function log( $arglist ) { 95 $log = new STDClass(); 96 $log->data = $arglist; 97 $backtrace = debug_backtrace(); 98 $log->backtrace = $backtrace[1]; 99 100 $this->logged[] = $log; 101 } 102 103 } 104 105 106 /** 107 * Used to save errors and warnings information, if any. 49 108 * @package KB_Debug 50 109 */ … … 64 123 */ 65 124 private $counters; 125 126 /** 127 * Warning in case an existing error handler is removed. 128 * @access private 129 * @var String 130 */ 131 private $message; 66 132 67 133 /** … … 77 143 $this->counters->notices = 0; 78 144 79 add_action( 'shutdown', Array( &$this, 'display' ) ); 80 set_error_handler( Array( &$this, 'log' ) ); 145 add_action( 'shutdown', Array( &$this, 'display' ), 99 ); 146 $original_handler = set_error_handler( Array( &$this, 'log' ) ); 147 148 $this->message = ""; 149 if( $original_handler != NULL ) 150 $this->message = "<p>Warning: An existing error handler was replaced." . print_r( $original_handler, true ) . "</p>"; 81 151 82 152 wp_enqueue_style( 'kb-debug-css', KB_DEBUG_RELURL . "/kb-debug.css" ); … … 90 160 echo "<div class = 'kb-debug-box'><div class = 'effect-border'>"; 91 161 echo "<h2>Errors and Warnings</h2>"; 162 echo $this->message; 92 163 echo "<ul>"; 93 164 foreach( $this->logged as $log ) { … … 112 183 echo "<pre style = 'max-height: 100px;'>"; print_r($log['context']); echo "</pre>"; 113 184 114 115 185 echo "</li>"; 116 186 } … … 170 240 171 241 add_action( 'all', Array( &$this, 'log' ) ); 172 add_action( 'shutdown', Array( &$this, 'display' ) );242 add_action( 'shutdown', Array( &$this, 'display' ), 100 ); 173 243 174 244 wp_enqueue_style( 'kb-debug-css', KB_DEBUG_RELURL . "/kb-debug.css" ); … … 228 298 */ 229 299 if (defined ('WP_DEBUG') && WP_DEBUG) { 230 if( isset( $_GET['KB_Debug_Errors'] ) ) 300 301 /** 302 * Call this function to save any data. Records calling information via a stack trace. 303 */ 304 function kb_debug() { 305 static $kdb; 306 if ( !isset( $kdb ) ) $kdb = new KB_Debug(); 307 308 $kdb->log( func_get_args() ); 309 } 310 311 if( isset( $_GET['KB_Debug_Errors'] ) || ( defined( 'KB_DEBUG' ) && KB_DEBUG ) ) 231 312 new KB_Debug_Errors(); 232 if( isset( $_GET['KB_Debug_Hooks'] ) )313 if( isset( $_GET['KB_Debug_Hooks'] ) || ( defined( 'KB_DEBUG' ) && KB_DEBUG ) ) 233 314 new KB_Debug_Hooks(); 234 315 } 235 236 237 /* 2. Reset capabilities to initial state if KB_RESET_CAPS is set in $_GET */238 239 /**240 * Reverts capabilities to default state.241 *242 * Useful while debugging.243 */244 function kb_reset_caps() {245 global $wpdb;246 $key = $wpdb->prefix . 'user_roles';247 248 //Bye, bye, existing caps249 delete_option( $key );250 251 //Repopulate252 require_once( "/home/kunalb/dev/eventpress/wp-admin/includes/schema.php" );253 populate_roles();254 }255 if (isset( $_GET['KB_RESET_CAPS'] ))256 add_action( 'init', kb_reset_caps );
Note: See TracChangeset
for help on using the changeset viewer.