Created
April 7, 2021 20:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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