Skip to content

Commit

Permalink
Load QM plugin before others
Browse files Browse the repository at this point in the history
Allow QM output on login screen
  • Loading branch information
johnbillion committed May 23, 2012
1 parent 43050a7 commit e3ebf96
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions query-monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: Query Monitor
Description: Monitoring of database queries, hooks, conditionals and more.
Version: 2.2.4
Version: 2.2.5
Author: John Blackbourn
Author URI: http://lud.icro.us/
Text Domain: query-monitor
Expand Down Expand Up @@ -37,18 +37,32 @@
* Template file name and body classes
* Transient update calls
@ TODO:
* Display queries from page loads before wp_redirect()
* Display queries from AJAX calls
* Show queried object info
* Show hooks attached to some selected filters, eg request, parse_request
* Add 'Component' filter to PHP errors list
* Change 'Function' to 'Caller'
*/

class QueryMonitor {

function __construct() {

# Actions
add_action( 'init', array( $this, 'init' ) );
add_action( 'admin_footer', array( $this, 'register_output' ), 999 );
add_action( 'wp_footer', array( $this, 'register_output' ), 999 );
add_action( 'login_footer', array( $this, 'register_output' ), 999 );
add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 999 );

# Filters
add_filter( 'pre_update_option_active_plugins', array( $this, 'load_first' ) );
add_filter( 'pre_update_site_option_active_sitewide_plugins', array( $this, 'load_first_sitewide' ) );

register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );

Expand Down Expand Up @@ -78,14 +92,19 @@ function get_components() {
return $this->components;
}

function activate() {
function activate( $sitewide = false ) {

if ( $admins = $this->get_admins() )
$admins->add_cap( 'view_query_monitor' );

if ( !file_exists( WP_CONTENT_DIR . '/db.php' ) and function_exists( 'symlink' ) )
@symlink( $this->plugin_dir . '/wp-content/db.php', WP_CONTENT_DIR . '/db.php' );

if ( $sitewide )
update_site_option( 'active_sitewide_plugins', $this->load_first_sitewide( get_site_option( 'active_sitewide_plugins' ) ) );
else
update_option( 'active_plugins', $this->load_first( get_option( 'active_plugins' ) ) );

}

function deactivate() {
Expand Down Expand Up @@ -243,6 +262,35 @@ function output() {

}

function load_first( $plugins ) {

$f = preg_quote( basename( __FILE__ ) );

return array_merge(
preg_grep( '/' . $f . '$/', $plugins ),
preg_grep( '/' . $f . '$/', $plugins, PREG_GREP_INVERT )
);

}

function load_first_sitewide( $plugins ) {

$f = plugin_basename( __FILE__ );

if ( isset( $plugins[$f] ) ) {

unset( $plugins[$f] );

return array_merge( array(
$f => time(),
), $plugins );

} else {
return $plugins;
}

}

function wpv() {
return 'qm-wp-' . ( floatval( $GLOBALS['wp_version'] ) * 10 );
}
Expand Down

0 comments on commit e3ebf96

Please sign in to comment.