1 <?php
2
3 4 5 6 7 8 9
10
11
12
13 14 15 16 17 18 19 20 21 22
23
24 function vanilla_debug_list_hooked_functions ( $tag=false, $show_properties=false ) {
25
26 global $wp_filter;
27
28 if ( $tag ) {
29
30 $hook[$tag] = $wp_filter[$tag];
31
32 if ( ! is_array( $hook[$tag] ) ) {
33 return;
34 }
35
36 } else {
37
38 $hook = $wp_filter;
39 ksort( $hook );
40
41 }
42
43
44 foreach ( $hook as $tag => $priority ) {
45
46 echo '<pre class = "vanilla-debug">';
47 echo '<strong>' . $tag . ' </strong><br>';
48
49 ksort( $priority );
50
51 foreach ( $priority as $priority => $function ) {
52
53 echo '<br><strong>Priority: ' . $priority . '</strong><br>';
54
55 foreach ( $function as $name => $properties) {
56
57 echo '' . $name . '(…)<br>';
58
59 if ( $show_properties ) {
60 var_dump( $properties );
61 }
62
63 }
64 }
65
66 echo '</pre>';
67
68 }
69
70 }
71
72
73
74 75 76 77 78 79 80 81 82
83
84 function vanilla_debug_var_dump ( $thing, $type = false ) {
85
86 echo '<pre class = "vanilla-debug' . ( $type ? $type : '' ) . '">';
87 var_dump( $thing );
88 echo '</pre>';
89
90 }
91
92
93
94 95 96 97 98 99
100
101 function vanilla_debug_show_wp_usage_in_responsiville () {
102
103 if ( ! defined( 'VANILLA_DEBUG' ) || ! VANILLA_DEBUG ) {
104 return false;
105 }
106
107
108
109
110
111 $time = str_replace( ',', '.', timer_stop( 0, 2 ) );
112 $max_ram = ceil( memory_get_peak_usage( true ) / 1024 / 1024 );
113 $num_queries = get_num_queries();
114 $username = '—';
115
116 $current_user = wp_get_current_user();
117
118 if ( $current_user->ID != 0 ) {
119 $username = $current_user->user_login;
120 } ?>
121
122
123
124 <!--
125 ================================================================================
126 *
127 * WordPress resource usage in Responsiville debug panel.
128 *
129 ================================================================================
130 -->
131
132 <script type = "text/javascript">
133
134 jQuery( function () {
135
136 window.setTimeout( function () {
137
138 jQuery( '.responsiville-debug-controls' ).append(
139
140 '<section class = "responsiville-debug-control responsiville-debug-wp">' +
141 '<table class = "vanilla" cellspacing = "0" cellpadding = "0"><tbody>' +
142 '<tr>' +
143 '<td>PHP time</td>' +
144 '<td>—></td>' +
145 '<td><?php echo $time; ?></td>' +
146 '<td class = "text-left">sec</td>' +
147 '</tr>' +
148 '<tr>' +
149 '<td>PHP RAM</td>' +
150 '<td>—></td>' +
151 '<td><?php echo $max_ram; ?></td>' +
152 '<td class = "text-left">mb</td>' +
153 '</tr>' +
154 '<tr>' +
155 '<td>MySQL queries</td>' +
156 '<td>—></td>' +
157 '<td><?php echo $num_queries; ?></td>' +
158 '<td class = "text-left">#</td>' +
159 '</tr>' +
160 '<tr>' +
161 '<td>WP user</td>' +
162 '<td>—></td>' +
163 '<td><?php echo $username; ?></td>' +
164 '<td class = "text-left"></td>' +
165 '</tr>' +
166 '</tbody></table>' +
167 '</section>'
168
169 );
170 }, 0 );
171
172 });
173
174 </script><?php
175
176 }
177
178 ?>