=' ) ) { require_once __DIR__ . '/qm4.php'; } else { require_once __DIR__ . '/qm3.php'; } if ( ! defined( 'SQLITE_QUERY_MONITOR_LOADED' ) ) { define( 'SQLITE_QUERY_MONITOR_LOADED', true ); } } if ( function_exists( 'add_action' ) ) { add_action( 'plugins_loaded', 'register_sqlite_enhancements_for_query_monitor' ); } /* * On a multisite install, we can't easily determine the current site eagerly. * Therefore, let's bail out and let Query Monitor activate later as a plugin. */ if ( is_multisite() ) { return; } /* * Now, let's try to load Query Monitor eagerly, to start logging queries early. * When the plugin is installed, we will check the database if it is also active. */ global $wpdb; if ( ! isset( $wpdb ) ) { return; } // Check if Query Monitor is installed. if ( defined( 'WP_PLUGIN_DIR' ) ) { $plugins_dir = WP_PLUGIN_DIR; } else { $plugins_dir = WP_CONTENT_DIR . '/plugins'; } $qm_dir = "{$plugins_dir}/query-monitor"; $qm_php = "{$qm_dir}/classes/PHP.php"; if ( ! is_readable( $qm_php ) ) { return; } // Check if Query Monitor is active. if ( null === $wpdb->options ) { global $table_prefix; $wpdb->set_prefix( $table_prefix ?? '' ); } $query_monitor_active = false; try { // Make sure no errors are displayed when the query fails. $show_errors = $wpdb->hide_errors(); $value = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", 'active_plugins' ) ); $wpdb->show_errors( $show_errors ); if ( null !== $value ) { $query_monitor_active = in_array( 'query-monitor/query-monitor.php', unserialize( $value->option_value ), true ); } } catch ( Throwable $e ) { return; } if ( ! $query_monitor_active ) { return; } // Load Query Monitor eagerly (as per the original "db.php" file). require_once $qm_php; if ( ! QM_PHP::version_met() ) { return; } if ( ! file_exists( "{$qm_dir}/vendor/autoload.php" ) ) { add_action( 'all_admin_notices', 'QM_PHP::vendor_nope' ); return; } require_once "{$qm_dir}/vendor/autoload.php"; if ( ! class_exists( 'QM_Backtrace' ) ) { return; } if ( ! defined( 'SAVEQUERIES' ) ) { define( 'SAVEQUERIES', true ); } // Mark the Query Monitor integration as loaded. define( 'SQLITE_QUERY_MONITOR_LOADED', true );