init() public static method

public static init ( $file = null )
/**
 * Require the plugin files for Query Monitor, faking a
 * plugin activation, if it's the first time.
 */
function wpcom_vip_qm_require()
{
    /**
     * Filter whether Query Monitor is activated; return true,
     * if QM should be activated.
     *
     * @param bool $enable False by default
     */
    if (!apply_filters('wpcom_vip_qm_enable', false)) {
        return;
    }
    if (!defined('SAVEQUERIES')) {
        define('SAVEQUERIES', true);
    }
    // For hyperdb, which doesn't use SAVEQUERIES
    global $wpdb;
    $wpdb->save_queries = SAVEQUERIES;
    $wpcom_vip_qm_file = __DIR__ . '/query-monitor/query-monitor.php';
    require_once $wpcom_vip_qm_file;
    // Because we're including Query Monitor as an MU plugin, we need to
    // manually call the `activate` method on `activation`.
    if (0 === get_option('wpcom_vip_qm_activated', 0)) {
        QueryMonitor::init($wpcom_vip_qm_file)->activate(true);
        update_option('wpcom_vip_qm_activated', 1, true);
    }
    // We don't want to share our environment information via Query Monitor
    remove_filter('qm/collectors', 'register_qm_collector_environment', 20, 2);
    // We know we haven't got the QM DB drop-in in place, so don't show the message
    add_filter('qm/show_extended_query_prompt', '__return_false');
}
Beispiel #2
0
function register_qm_collectors_debug_bar()
{
    global $debug_bar;
    if (class_exists('Debug_Bar') || qm_debug_bar_being_activated()) {
        return;
    }
    $collectors = QM_Collectors::init();
    $qm = QueryMonitor::init();
    require_once $qm->plugin_path('classes/debug_bar.php');
    $debug_bar = new Debug_Bar();
    $redundant = array('debug_bar_actions_addon_panel', 'debug_bar_remote_requests_panel', 'debug_bar_screen_info_panel', 'ps_listdeps_debug_bar_panel');
    foreach ($debug_bar->panels as $panel) {
        $panel_id = strtolower(get_class($panel));
        if (in_array($panel_id, $redundant)) {
            continue;
        }
        $collector = new QM_Collector_Debug_Bar();
        $collector->set_id("debug_bar_{$panel_id}");
        $collector->set_panel($panel);
        $collectors->add($collector);
    }
}
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
defined('ABSPATH') or die;
$qm_dir = dirname(__FILE__);
# No autoloaders for us. See https://github.com/johnbillion/query-monitor/issues/7
foreach (array('Plugin', 'Activation', 'Util') as $qm_class) {
    require_once "{$qm_dir}/classes/{$qm_class}.php";
}
QM_Activation::init(__FILE__);
if (defined('QM_DISABLED') and QM_DISABLED) {
    return;
}
if ('cli' === php_sapi_name() && !defined('QM_TESTS')) {
    # 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. This will hopefully change in a future version of QM.
    return;
}
if (defined('DOING_CRON') && DOING_CRON) {
    # Let's not load QM during cron events for the same reason as above.
    return;
}
foreach (array('QueryMonitor', 'Backtrace', 'Collectors', 'Collector', 'Dispatchers', 'Dispatcher', 'Output') as $qm_class) {
    require_once "{$qm_dir}/classes/{$qm_class}.php";
}
QueryMonitor::init(__FILE__);