Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhughes/29b56529fca5ff40932290ff3c0407cf to your computer and use it in GitHub Desktop.
Save barryhughes/29b56529fca5ff40932290ff3c0407cf to your computer and use it in GitHub Desktop.
Make Query Monitor available for logged out users. Useful alternative when Query Monitor's own authentication cookie-based support for the same thing is not enough.
<?php
/**
* Makes Query Monitor output available to all users.
*
* This can, for example, be added to mu-plugins/query-monitor.php (and can
* easily be disabled by changing 'init' to 'xinit', or commenting the whole
* thing out, or adding a return statement, etc).
*
* Reasons you might use this instead of simply setting Query Monitor's own
* authentication cookie include cases where you are debugging locally and
* wish to remain logged in as an admin user in one tab, and/or are also using
* one or more private windows (or container tabs) concurrently.
*/
add_action( 'init', function() {
$user = wp_get_current_user();
if ( is_object( $user ) ) {
$user->add_cap( 'view_query_monitor' );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment