1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Debug Display |
---|
4 | Plugin URI: http://www.santosj.name |
---|
5 | Description: Display log messages |
---|
6 | Author: Jacob Santos |
---|
7 | Version: 1.0 |
---|
8 | Author URI: http://www.santosj.name |
---|
9 | */ |
---|
10 | |
---|
11 | add_action('shutdown', 'wp_log_shutdown'); |
---|
12 | |
---|
13 | /** |
---|
14 | * wp_log_shutdown() - Display the log messages to the user |
---|
15 | * |
---|
16 | * Will display the messages in the theme footer ('wp_footer'). |
---|
17 | * |
---|
18 | * @since 2.5 |
---|
19 | */ |
---|
20 | function wp_log_shutdown() { |
---|
21 | // If WP_DEBUG is not defined, then don't process log message |
---|
22 | if( !defined('WP_DEBUG') ) |
---|
23 | return; |
---|
24 | |
---|
25 | global $wp_log_messages, $wp_plugin_log_messages; |
---|
26 | |
---|
27 | if( !is_array($wp_log_messages) || empty($wp_log_messages) ) |
---|
28 | return; |
---|
29 | |
---|
30 | $log_content = ''; |
---|
31 | |
---|
32 | uasort($wp_log_messages, 'strnatcasecmp'); |
---|
33 | |
---|
34 | $log_content .= apply_filters('wp_log_display_wordpress', '<h1>WordPress Log Messages</h1>'); |
---|
35 | |
---|
36 | $log_content .= apply_filters('wp_log_display_start', '<div align="left" style="font-size: 10px;">'); |
---|
37 | $log_content .= wp_log_display( $wp_log_messages ); |
---|
38 | $log_content .= apply_filters('wp_log_display_end', '</div>'); |
---|
39 | |
---|
40 | $log_content .= apply_filters('wp_log_display_plugins', '<h1>Plugin Log Messages</h1>'); |
---|
41 | |
---|
42 | $log_content .= apply_filters('wp_log_display_start', '<div align="left" style="font-size: 10px;">'); |
---|
43 | $log_content .= wp_log_display( $wp_plugin_log_messages ); |
---|
44 | $log_content .= apply_filters('wp_log_display_end', '</div>'); |
---|
45 | |
---|
46 | echo $log_content; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * wp_log_display() - Converts log message array to display form |
---|
51 | * |
---|
52 | * @since 2.5 |
---|
53 | * @param array $log_messages |
---|
54 | * @return string |
---|
55 | */ |
---|
56 | function wp_log_display($log_messages) { |
---|
57 | $log_content = ''; |
---|
58 | |
---|
59 | foreach( $log_messages as $type => $log_type_array ) { |
---|
60 | $log_type = apply_filters('wp_log_type', true, $type); |
---|
61 | $log_type_with_type = apply_filters("wp_log_{$type}_type", true); |
---|
62 | |
---|
63 | // Catch types that shouldn't have been logged. |
---|
64 | if( false === $log_type || false === $log_type_with_type ) |
---|
65 | continue; |
---|
66 | |
---|
67 | $log_content .= apply_filters('wp_log_display_type_start', "<h2>{$type}</h2><ul>", $type); |
---|
68 | |
---|
69 | uksort($log_type_array, 'strnatcasecmp'); |
---|
70 | |
---|
71 | foreach( $log_type_array as $severity => $log_messages ) { |
---|
72 | |
---|
73 | // Catch severity items that shouldn't be displayed |
---|
74 | if ( false === apply_filters('wp_log_severity', true, $severity) ) |
---|
75 | continue; |
---|
76 | |
---|
77 | $severity_display = wp_log_severity_display_name($severity); |
---|
78 | $log_content .= apply_filters('wp_log_display_severity_start', '<li><h3>' . $severity_display . '</h3><br /><br />', $severity, $severity_display); |
---|
79 | |
---|
80 | $log_content .= "<ol>\n"; |
---|
81 | |
---|
82 | foreach( $log_messages as $log_message ) { |
---|
83 | $log_content .= "<li>\n"; |
---|
84 | // See if we need to add the backtrace. |
---|
85 | $log_content .= '<strong>'. $log_message[0] .'</strong><br /><br />'; |
---|
86 | $backtrace = apply_filters('wp_log_backtrace', $log_message[1]); |
---|
87 | |
---|
88 | // Format the backtrace display |
---|
89 | $log_content .= "<table style=\"font-size: 10px;\">\n<tr><th>file</th><th>line</th><th>function</th><th>args</th></tr>\n"; |
---|
90 | |
---|
91 | for($i=0; $i < count($backtrace); ++$i) { |
---|
92 | if( 'wp_log' == $backtrace_message['function'] ) |
---|
93 | continue; |
---|
94 | |
---|
95 | $log_content .= "<tr". ( ($i%2) == 0 ? ' style="background-color:#ffffff;"' : '') .">\n"; |
---|
96 | $log_content .= "<td>". $backtrace[$i]['file'] ."</td>\n"; |
---|
97 | $log_content .= "<td>". $backtrace[$i]['line'] ."</td>\n"; |
---|
98 | $log_content .= "<td>". $backtrace[$i]['function'] ."</td>\n"; |
---|
99 | $log_content .= "<td>". implode("<br />\n", $backtrace[$i]['args']) ."</td>\n"; |
---|
100 | $log_content .= "</tr>"; |
---|
101 | } |
---|
102 | |
---|
103 | $log_content .= "</table><br /><br />\n"; |
---|
104 | $log_content .= "</li>\n"; |
---|
105 | } |
---|
106 | $log_content .= "</ol>\n"; |
---|
107 | |
---|
108 | $log_content .= apply_filters('wp_log_display_severity_end', '</li>'); |
---|
109 | } |
---|
110 | |
---|
111 | $log_content .= apply_filters('wp_log_display_type_end', "</ul>\n\n"); |
---|
112 | } |
---|
113 | |
---|
114 | return $log_content; |
---|
115 | } |
---|