Skip to content

Commit 1dc9eec

Browse files
authored
[Query monitor] Tolerate null $value in boot.php (#219)
PR #217 added a line `global $wpdb` to `integration/query-monitor/boot.php` which triggered this warning in WordPress Playground multisite tests: ``` + <b>Warning</b>: Attempt to read property "option_value" on null in <b>/internal/shared/sqlite-database-integration/integrations/query-monitor/boot.php</b> on line <b>80</b><br /> ``` Removing either `global $wpdb` or guarding against a null `$value` solves the failure. I assume there's a reason for adding `global $wpdb` so, in this PR, I'm adding a guard against a null value.
2 parents 71e6e8d + be57d38 commit 1dc9eec

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

integrations/query-monitor/boot.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,23 @@
6969

7070
$query_monitor_active = false;
7171
try {
72-
$value = $wpdb->get_row(
72+
$value = $wpdb->get_row(
7373
$wpdb->prepare(
7474
"SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
7575
'active_plugins'
7676
)
7777
);
78-
$query_monitor_active = in_array(
79-
'query-monitor/query-monitor.php',
80-
unserialize( $value->option_value ),
81-
true
82-
);
78+
/**
79+
* $value may be null during WordPress Playground multisite setup.
80+
* @see https://github.com/WordPress/sqlite-database-integration/pull/219.
81+
*/
82+
if ( null !== $value ) {
83+
$query_monitor_active = in_array(
84+
'query-monitor/query-monitor.php',
85+
unserialize( $value->option_value ),
86+
true
87+
);
88+
}
8389
} catch ( Throwable $e ) {
8490
return;
8591
}

0 commit comments

Comments
 (0)