Query Monitor - Version 2.7.2

Version Description

  • Implement a shutdown handler for PHP errors to avoid fatals being unintentionally hidden when display_errors is on.
  • Don't attempt to do anything with scripts and styles if a corresponding header action hasn't fired.
  • Don't sort the enqueued scripts and styles, so they're output in the order in which they're enqueued.
  • For the time being, let's not load QM when using the CLI because we've no persistent storage and no means of outputting collected data on the CLI.
  • Call static methods using their class name, not a variable. Fixes compatibility with PHP 5.2.
Download this release

Release Info

Developer johnbillion
Plugin Icon 128x128 Query Monitor
Version 2.7.2
Comparing to
See all releases

Code changes from version 2.7.1 to 2.7.2

collectors/assets.php CHANGED
@@ -38,6 +38,10 @@ class QM_Collector_Assets extends QM_Collector {
38
  public function action_print_footer_scripts() {
39
  global $wp_scripts, $wp_styles;
40
 
 
 
 
 
41
  // @TODO remove the need for these raw scripts & styles to be collected
42
  $this->data['raw']['scripts'] = $wp_scripts;
43
  $this->data['raw']['styles'] = $wp_styles;
@@ -56,8 +60,6 @@ class QM_Collector_Assets extends QM_Collector {
56
  foreach ( array( 'header', 'footer' ) as $position ) {
57
  if ( empty( $this->data[ $position ][ $type ] ) ) {
58
  $this->data[ $position ][ $type ] = array();
59
- } else {
60
- sort( $this->data[ $position ][ $type ] );
61
  }
62
  }
63
  $raw = $this->data['raw'][ $type ];
@@ -76,13 +78,11 @@ class QM_Collector_Assets extends QM_Collector {
76
 
77
  if ( !empty( $broken ) ) {
78
  $this->data['broken'][ $type ] = array_unique( $broken );
79
- sort( $this->data['broken'][ $type ] );
80
  }
81
  }
82
 
83
  if ( ! empty( $missing ) ) {
84
  $this->data['missing'][ $type ] = array_unique( $missing );
85
- sort( $this->data['missing'][ $type ] );
86
  foreach ( $this->data['missing'][ $type ] as $handle ) {
87
  $raw->add( $handle, false );
88
  }
38
  public function action_print_footer_scripts() {
39
  global $wp_scripts, $wp_styles;
40
 
41
+ if ( empty( $this->data['header'] ) ) {
42
+ return;
43
+ }
44
+
45
  // @TODO remove the need for these raw scripts & styles to be collected
46
  $this->data['raw']['scripts'] = $wp_scripts;
47
  $this->data['raw']['styles'] = $wp_styles;
60
  foreach ( array( 'header', 'footer' ) as $position ) {
61
  if ( empty( $this->data[ $position ][ $type ] ) ) {
62
  $this->data[ $position ][ $type ] = array();
 
 
63
  }
64
  }
65
  $raw = $this->data['raw'][ $type ];
78
 
79
  if ( !empty( $broken ) ) {
80
  $this->data['broken'][ $type ] = array_unique( $broken );
 
81
  }
82
  }
83
 
84
  if ( ! empty( $missing ) ) {
85
  $this->data['missing'][ $type ] = array_unique( $missing );
 
86
  foreach ( $this->data['missing'][ $type ] as $handle ) {
87
  $raw->add( $handle, false );
88
  }
collectors/php_errors.php CHANGED
@@ -40,6 +40,7 @@ class QM_Collector_PHP_Errors extends QM_Collector {
40
 
41
  parent::__construct();
42
  set_error_handler( array( $this, 'error_handler' ) );
 
43
 
44
  $this->display_errors = ini_get( 'display_errors' );
45
  ini_set( 'display_errors', 0 );
@@ -111,6 +112,46 @@ class QM_Collector_PHP_Errors extends QM_Collector {
111
 
112
  }
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  public function tear_down() {
115
  parent::tear_down();
116
  ini_set( 'display_errors', $this->display_errors );
40
 
41
  parent::__construct();
42
  set_error_handler( array( $this, 'error_handler' ) );
43
+ register_shutdown_function( array( $this, 'shutdown_handler' ) );
44
 
45
  $this->display_errors = ini_get( 'display_errors' );
46
  ini_set( 'display_errors', 0 );
112
 
113
  }
114
 
115
+ public function shutdown_handler() {
116
+
117
+ $e = error_get_last();
118
+
119
+ if ( empty( $this->display_errors ) ) {
120
+ return;
121
+ }
122
+
123
+ if ( empty( $e ) or ! ( $e['type'] & ( E_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR ) ) ) {
124
+ return;
125
+ }
126
+
127
+ if ( $e['type'] & E_RECOVERABLE_ERROR ) {
128
+ $error = 'Catchable fatal error';
129
+ } else {
130
+ $error = 'Fatal error';
131
+ }
132
+
133
+ if ( function_exists( 'xdebug_print_function_stack' ) ) {
134
+
135
+ xdebug_print_function_stack( sprintf( '%1$s: %2$s in %3$s on line %4$d. Output triggered ',
136
+ $error,
137
+ $e['message'],
138
+ $e['file'],
139
+ $e['line']
140
+ ) );
141
+
142
+ } else {
143
+
144
+ printf( '<br /><b>%1$s</b>: %2$s in <b>%3$s</b> on line <b>%4$d</b><br />',
145
+ htmlentities( $error ),
146
+ htmlentities( $e['message'] ),
147
+ htmlentities( $e['file'] ),
148
+ intval( $e['line'] )
149
+ );
150
+
151
+ }
152
+
153
+ }
154
+
155
  public function tear_down() {
156
  parent::tear_down();
157
  ini_set( 'display_errors', $this->display_errors );
output/headers/php_errors.php CHANGED
@@ -66,7 +66,7 @@ class QM_Output_Headers_PHP_Errors extends QM_Output_Headers {
66
  }
67
 
68
  function register_qm_output_headers_php_errors( array $output, QM_Collectors $collectors ) {
69
- if ( $collector = $collectors::get( 'php_errors' ) ) {
70
  $output['php_errors'] = new QM_Output_Headers_PHP_Errors( $collector );
71
  }
72
  return $output;
66
  }
67
 
68
  function register_qm_output_headers_php_errors( array $output, QM_Collectors $collectors ) {
69
+ if ( $collector = QM_Collectors::get( 'php_errors' ) ) {
70
  $output['php_errors'] = new QM_Output_Headers_PHP_Errors( $collector );
71
  }
72
  return $output;
output/headers/redirects.php CHANGED
@@ -33,7 +33,7 @@ class QM_Output_Headers_Redirects extends QM_Output_Headers {
33
  }
34
 
35
  function register_qm_output_headers_redirects( array $output, QM_Collectors $collectors ) {
36
- if ( $collector = $collectors::get( 'redirects' ) ) {
37
  $output['redirects'] = new QM_Output_Headers_Redirects( $collector );
38
  }
39
  return $output;
33
  }
34
 
35
  function register_qm_output_headers_redirects( array $output, QM_Collectors $collectors ) {
36
+ if ( $collector = QM_Collectors::get( 'redirects' ) ) {
37
  $output['redirects'] = new QM_Output_Headers_Redirects( $collector );
38
  }
39
  return $output;
output/html/admin.php CHANGED
@@ -125,7 +125,7 @@ class QM_Output_Html_Admin extends QM_Output_Html {
125
  }
126
 
127
  function register_qm_output_html_admin( array $output, QM_Collectors $collectors ) {
128
- if ( $collector = $collectors::get( 'admin' ) ) {
129
  $output['admin'] = new QM_Output_Html_Admin( $collector );
130
  }
131
  return $output;
125
  }
126
 
127
  function register_qm_output_html_admin( array $output, QM_Collectors $collectors ) {
128
+ if ( $collector = QM_Collectors::get( 'admin' ) ) {
129
  $output['admin'] = new QM_Output_Html_Admin( $collector );
130
  }
131
  return $output;
output/html/assets.php CHANGED
@@ -193,7 +193,7 @@ class QM_Output_Html_Assets extends QM_Output_Html {
193
  }
194
 
195
  function register_qm_output_html_assets( array $output, QM_Collectors $collectors ) {
196
- if ( $collector = $collectors::get( 'assets' ) ) {
197
  $output['assets'] = new QM_Output_Html_Assets( $collector );
198
  }
199
  return $output;
193
  }
194
 
195
  function register_qm_output_html_assets( array $output, QM_Collectors $collectors ) {
196
+ if ( $collector = QM_Collectors::get( 'assets' ) ) {
197
  $output['assets'] = new QM_Output_Html_Assets( $collector );
198
  }
199
  return $output;
output/html/conditionals.php CHANGED
@@ -91,7 +91,7 @@ class QM_Output_Html_Conditionals extends QM_Output_Html {
91
  }
92
 
93
  function register_qm_output_html_conditionals( array $output, QM_Collectors $collectors ) {
94
- if ( $collector = $collectors::get( 'conditionals' ) ) {
95
  $output['conditionals'] = new QM_Output_Html_Conditionals( $collector );
96
  }
97
  return $output;
91
  }
92
 
93
  function register_qm_output_html_conditionals( array $output, QM_Collectors $collectors ) {
94
+ if ( $collector = QM_Collectors::get( 'conditionals' ) ) {
95
  $output['conditionals'] = new QM_Output_Html_Conditionals( $collector );
96
  }
97
  return $output;
output/html/db_callers.php CHANGED
@@ -122,7 +122,7 @@ class QM_Output_Html_DB_Callers extends QM_Output_Html {
122
  }
123
 
124
  function register_qm_output_html_db_callers( array $output, QM_Collectors $collectors ) {
125
- if ( $collector = $collectors::get( 'db_callers' ) ) {
126
  $output['db_callers'] = new QM_Output_Html_DB_Callers( $collector );
127
  }
128
  return $output;
122
  }
123
 
124
  function register_qm_output_html_db_callers( array $output, QM_Collectors $collectors ) {
125
+ if ( $collector = QM_Collectors::get( 'db_callers' ) ) {
126
  $output['db_callers'] = new QM_Output_Html_DB_Callers( $collector );
127
  }
128
  return $output;
output/html/db_components.php CHANGED
@@ -123,7 +123,7 @@ class QM_Output_Html_DB_Components extends QM_Output_Html {
123
  }
124
 
125
  function register_qm_output_html_db_components( array $output, QM_Collectors $collectors ) {
126
- if ( $collector = $collectors::get( 'db_components' ) ) {
127
  $output['db_components'] = new QM_Output_Html_DB_Components( $collector );
128
  }
129
  return $output;
123
  }
124
 
125
  function register_qm_output_html_db_components( array $output, QM_Collectors $collectors ) {
126
+ if ( $collector = QM_Collectors::get( 'db_components' ) ) {
127
  $output['db_components'] = new QM_Output_Html_DB_Components( $collector );
128
  }
129
  return $output;
output/html/db_queries.php CHANGED
@@ -411,7 +411,7 @@ class QM_Output_Html_DB_Queries extends QM_Output_Html {
411
  }
412
 
413
  function register_qm_output_html_db_queries( array $output, QM_Collectors $collectors ) {
414
- if ( $collector = $collectors::get( 'db_queries' ) ) {
415
  $output['db_queries'] = new QM_Output_Html_DB_Queries( $collector );
416
  }
417
  return $output;
411
  }
412
 
413
  function register_qm_output_html_db_queries( array $output, QM_Collectors $collectors ) {
414
+ if ( $collector = QM_Collectors::get( 'db_queries' ) ) {
415
  $output['db_queries'] = new QM_Output_Html_DB_Queries( $collector );
416
  }
417
  return $output;
output/html/debug_bar.php CHANGED
@@ -61,7 +61,7 @@ function register_qm_output_html_debug_bar( array $output, QM_Collectors $collec
61
 
62
  foreach ( $debug_bar->panels as $panel ) {
63
  $panel_id = strtolower( get_class( $panel ) );
64
- $collector = $collectors::get( "debug_bar_{$panel_id}" );
65
 
66
  if ( $collector and $collector->is_visible() ) {
67
  $output["debug_bar_{$panel_id}"] = new QM_Output_Html_Debug_Bar( $collector );
61
 
62
  foreach ( $debug_bar->panels as $panel ) {
63
  $panel_id = strtolower( get_class( $panel ) );
64
+ $collector = QM_Collectors::get( "debug_bar_{$panel_id}" );
65
 
66
  if ( $collector and $collector->is_visible() ) {
67
  $output["debug_bar_{$panel_id}"] = new QM_Output_Html_Debug_Bar( $collector );
output/html/environment.php CHANGED
@@ -241,7 +241,7 @@ class QM_Output_Html_Environment extends QM_Output_Html {
241
  }
242
 
243
  function register_qm_output_html_environment( array $output, QM_Collectors $collectors ) {
244
- if ( $collector = $collectors::get( 'environment' ) ) {
245
  $output['environment'] = new QM_Output_Html_Environment( $collector );
246
  }
247
  return $output;
241
  }
242
 
243
  function register_qm_output_html_environment( array $output, QM_Collectors $collectors ) {
244
+ if ( $collector = QM_Collectors::get( 'environment' ) ) {
245
  $output['environment'] = new QM_Output_Html_Environment( $collector );
246
  }
247
  return $output;
output/html/hooks.php CHANGED
@@ -180,7 +180,7 @@ class QM_Output_Html_Hooks extends QM_Output_Html {
180
  }
181
 
182
  function register_qm_output_html_hooks( array $output, QM_Collectors $collectors ) {
183
- if ( $collector = $collectors::get( 'hooks' ) ) {
184
  $output['hooks'] = new QM_Output_Html_Hooks( $collector );
185
  }
186
  return $output;
180
  }
181
 
182
  function register_qm_output_html_hooks( array $output, QM_Collectors $collectors ) {
183
+ if ( $collector = QM_Collectors::get( 'hooks' ) ) {
184
  $output['hooks'] = new QM_Output_Html_Hooks( $collector );
185
  }
186
  return $output;
output/html/http.php CHANGED
@@ -202,7 +202,7 @@ class QM_Output_Html_HTTP extends QM_Output_Html {
202
  }
203
 
204
  function register_qm_output_html_http( array $output, QM_Collectors $collectors ) {
205
- if ( $collector = $collectors::get( 'http' ) ) {
206
  $output['http'] = new QM_Output_Html_HTTP( $collector );
207
  }
208
  return $output;
202
  }
203
 
204
  function register_qm_output_html_http( array $output, QM_Collectors $collectors ) {
205
+ if ( $collector = QM_Collectors::get( 'http' ) ) {
206
  $output['http'] = new QM_Output_Html_HTTP( $collector );
207
  }
208
  return $output;
output/html/overview.php CHANGED
@@ -112,7 +112,7 @@ class QM_Output_Html_Overview extends QM_Output_Html {
112
  }
113
 
114
  function register_qm_output_html_overview( array $output, QM_Collectors $collectors ) {
115
- if ( $collector = $collectors::get( 'overview' ) ) {
116
  $output['overview'] = new QM_Output_Html_Overview( $collector );
117
  }
118
  return $output;
112
  }
113
 
114
  function register_qm_output_html_overview( array $output, QM_Collectors $collectors ) {
115
+ if ( $collector = QM_Collectors::get( 'overview' ) ) {
116
  $output['overview'] = new QM_Output_Html_Overview( $collector );
117
  }
118
  return $output;
output/html/php_errors.php CHANGED
@@ -152,7 +152,7 @@ class QM_Output_Html_PHP_Errors extends QM_Output_Html {
152
  }
153
 
154
  function register_qm_output_html_php_errors( array $output, QM_Collectors $collectors ) {
155
- if ( $collector = $collectors::get( 'php_errors' ) ) {
156
  $output['php_errors'] = new QM_Output_Html_PHP_Errors( $collector );
157
  }
158
  return $output;
152
  }
153
 
154
  function register_qm_output_html_php_errors( array $output, QM_Collectors $collectors ) {
155
+ if ( $collector = QM_Collectors::get( 'php_errors' ) ) {
156
  $output['php_errors'] = new QM_Output_Html_PHP_Errors( $collector );
157
  }
158
  return $output;
output/html/request.php CHANGED
@@ -170,7 +170,7 @@ class QM_Output_Html_Request extends QM_Output_Html {
170
  }
171
 
172
  function register_qm_output_html_request( array $output, QM_Collectors $collectors ) {
173
- if ( $collector = $collectors::get( 'request' ) ) {
174
  $output['request'] = new QM_Output_Html_Request( $collector );
175
  }
176
  return $output;
170
  }
171
 
172
  function register_qm_output_html_request( array $output, QM_Collectors $collectors ) {
173
+ if ( $collector = QM_Collectors::get( 'request' ) ) {
174
  $output['request'] = new QM_Output_Html_Request( $collector );
175
  }
176
  return $output;
output/html/theme.php CHANGED
@@ -103,7 +103,7 @@ class QM_Output_Html_Theme extends QM_Output_Html {
103
  }
104
 
105
  function register_qm_output_html_theme( array $output, QM_Collectors $collectors ) {
106
- if ( $collector = $collectors::get( 'theme' ) ) {
107
  $output['theme'] = new QM_Output_Html_Theme( $collector );
108
  }
109
  return $output;
103
  }
104
 
105
  function register_qm_output_html_theme( array $output, QM_Collectors $collectors ) {
106
+ if ( $collector = QM_Collectors::get( 'theme' ) ) {
107
  $output['theme'] = new QM_Output_Html_Theme( $collector );
108
  }
109
  return $output;
output/html/transients.php CHANGED
@@ -107,7 +107,7 @@ class QM_Output_Html_Transients extends QM_Output_Html {
107
  }
108
 
109
  function register_qm_output_html_transients( array $output, QM_Collectors $collectors ) {
110
- if ( $collector = $collectors::get( 'transients' ) ) {
111
  $output['transients'] = new QM_Output_Html_Transients( $collector );
112
  }
113
  return $output;
107
  }
108
 
109
  function register_qm_output_html_transients( array $output, QM_Collectors $collectors ) {
110
+ if ( $collector = QM_Collectors::get( 'transients' ) ) {
111
  $output['transients'] = new QM_Output_Html_Transients( $collector );
112
  }
113
  return $output;
query-monitor.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Query Monitor
4
  Description: Monitoring of database queries, hooks, conditionals and more.
5
- Version: 2.7.1
6
  Plugin URI: https://querymonitor.com/
7
  Author: John Blackbourn
8
  Author URI: https://johnblackbourn.com/
@@ -30,6 +30,12 @@ if ( defined( 'QM_DISABLED' ) and QM_DISABLED ) {
30
  return;
31
  }
32
 
 
 
 
 
 
 
33
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
34
  $qm_dir = dirname( __FILE__ );
35
  foreach ( array( 'Backtrace', 'Collectors', 'Collector', 'Plugin', 'Util', 'Dispatchers', 'Dispatcher', 'Output' ) as $qm_class ) {
2
  /*
3
  Plugin Name: Query Monitor
4
  Description: Monitoring of database queries, hooks, conditionals and more.
5
+ Version: 2.7.2
6
  Plugin URI: https://querymonitor.com/
7
  Author: John Blackbourn
8
  Author URI: https://johnblackbourn.com/
30
  return;
31
  }
32
 
33
+ if ( 'cli' == php_sapi_name() ) {
34
+ # For the time being, let's not load QM when using the CLI because we've no persistent storage and no means of
35
+ # outputting collected data on the CLI. This will change in a future version of QM.
36
+ return;
37
+ }
38
+
39
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
40
  $qm_dir = dirname( __FILE__ );
41
  foreach ( array( 'Backtrace', 'Collectors', 'Collector', 'Plugin', 'Util', 'Dispatchers', 'Dispatcher', 'Output' ) as $qm_class ) {
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: johnbillion
3
  Tags: debug, debug-bar, debugging, development, developer, performance, profiler, profiling, queries, query monitor
4
  Requires at least: 3.5
5
  Tested up to: 4.1.1
6
- Stable tag: 2.7.1
7
  License: GPLv2 or later
8
 
9
  View debugging and performance information on database queries, hooks, conditionals, HTTP requests, redirects and more.
@@ -156,6 +156,13 @@ No, I do not accept donations. If you like the plugin, I'd love for you to [leav
156
 
157
  == Changelog ==
158
 
 
 
 
 
 
 
 
159
  = 2.7.1 =
160
  * Display a warning (rather than triggering a fatal error) for scripts and style dependencies which have gone missing during the duration of the page load.
161
  * Tweak some more Debug Bar add-on styles.
3
  Tags: debug, debug-bar, debugging, development, developer, performance, profiler, profiling, queries, query monitor
4
  Requires at least: 3.5
5
  Tested up to: 4.1.1
6
+ Stable tag: 2.7.2
7
  License: GPLv2 or later
8
 
9
  View debugging and performance information on database queries, hooks, conditionals, HTTP requests, redirects and more.
156
 
157
  == Changelog ==
158
 
159
+ = 2.7.2 =
160
+ * Implement a shutdown handler for PHP errors to avoid fatals being unintentionally hidden when `display_errors` is on.
161
+ * Don't attempt to do anything with scripts and styles if a corresponding header action hasn't fired.
162
+ * Don't sort the enqueued scripts and styles, so they're output in the order in which they're enqueued.
163
+ * For the time being, let's not load QM when using the CLI because we've no persistent storage and no means of outputting collected data on the CLI.
164
+ * Call static methods using their class name, not a variable. Fixes compatibility with PHP 5.2.
165
+
166
  = 2.7.1 =
167
  * Display a warning (rather than triggering a fatal error) for scripts and style dependencies which have gone missing during the duration of the page load.
168
  * Tweak some more Debug Bar add-on styles.
wp-content/db.php CHANGED
@@ -29,6 +29,12 @@ if ( defined( 'QM_DISABLED' ) and QM_DISABLED ) {
29
  return;
30
  }
31
 
 
 
 
 
 
 
32
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
33
  $qm_dir = dirname( dirname( __FILE__ ) );
34
  if ( ! is_readable( $backtrace = "{$qm_dir}/classes/Backtrace.php" ) ) {
29
  return;
30
  }
31
 
32
+ if ( 'cli' == php_sapi_name() ) {
33
+ # For the time being, let's not load QM when using the CLI because we've no persistent storage and no means of
34
+ # outputting collected data on the CLI. This will change in a future version of QM.
35
+ return;
36
+ }
37
+
38
  # No autoloaders for us. See https://github.com/johnbillion/QueryMonitor/issues/7
39
  $qm_dir = dirname( dirname( __FILE__ ) );
40
  if ( ! is_readable( $backtrace = "{$qm_dir}/classes/Backtrace.php" ) ) {