Title: Enable Query Monitor
Author: WordPress VIP Documentation
Published: October 19, 2020
Last modified: August 4, 2025

---

 1. [Performance](https://docs.wpvip.com/performance/)
 2. [Query Monitor](https://docs.wpvip.com/performance/query-monitor/)
 3. Enable Query Monitor

#  Enable Query Monitor

[Query Monitor is a WordPress plugin](https://github.com/johnbillion/query-monitor)
that provides a developer tools panel for WordPress. It enables debugging of database
queries, PHP errors, warnings and notices, hooks and actions, block editor blocks,
enqueued scripts and stylesheets, HTTP API calls, and more.

[The listing for the Query Monitor plugin in the WordPress.org Plugins directory](https://wordpress.org/plugins/query-monitor/)
provides a more complete feature list and a guide for usage.

Query Monitor is installed on all WordPress environments by [VIP MU plugins](https://docs.wpvip.com/vip-go-mu-plugins/).

## Enable user access with VIP-CLI

Access to Query Monitor is limited to users that have a `view_query_monitor` capability
assigned to them.

[Use VIP-CLI to run a WP-CLI command](https://docs.wpvip.com/wp-cli-with-vip-cli/)
to add the `view_query_monitor` capability to user roles or to individual users.

### Enable access for specific roles

[Use the `wp cap add` WP-CLI command](https://developer.wordpress.org/cli/commands/cap/add/)
to add a capability on a per-role basis. In this command example the `view_query_monitor`
capability is added for all users with the Editor role.

    ```wp-block-preformatted
    vip @example-app.develop -- wp cap add editor view_query_monitor
    ```

### Enable access for specific users

[Use the `wp user add-cap` WP-CLI command](https://developer.wordpress.org/cli/commands/user/add-cap/)
to add a capability on a per-user basis. In this command example the `view_query_monitor`
capability is added for a user with the username “exampleuser”.

    ```wp-block-preformatted
    vip @example-app.develop -- wp user add-cap exampleuser view_query_monitor
    ```

## Enable user access through code

Access to Query Monitor can be enabled through code by hooking into the `[wpcom_vip_qm_enable](https://github.com/Automattic/vip-go-mu-plugins/blob/9ab01460d5e01645a71f6a035dbd2510f394e562/query-monitor.php#L53-L60)`
filter. The code should be added to a file in either an application’s [`plugins` directory](https://docs.wpvip.com/wordpress-skeleton/plugins-directory/)
or [the `client-mu-plugin` directory](https://docs.wpvip.com/wordpress-skeleton/client-mu-plugins-directory/).

This code example demonstrates how to enable access to Query Monitor for the user
roles `[vip_support](https://docs.wpvip.com/restricting-site-access/site-access-for-vip-support/)`
and Editor:

    ```lang-php
    <?php

    /**
     * Enable Query Monitor for a defined set of roles or users.
     * 
     * @param bool $enable Whether Query Monitor should be enabled.
     */
    function vip_custom_enable_query_monitor( $enable ) {

        $allowed_roles = array( 'vip_support', 'editor' );
    	// Optional, enable for specific user logins.
        // $allowed_users = array( 'dev_user_login', 'qa_user_login' );

        if ( is_user_logged_in() ) {
            $user  = wp_get_current_user();
            $login = $user->get('user_login');
            $roles = (array) $user->roles;

            // Allow if the user is assigned a role in the $allow_role array.
            if ( count( array_intersect( $roles, $allowed_roles ) ) > 0 ) {
                return true;
            }

            // Allow if the user's login is in the $allowed_users array.
            if ( isset( $allowed_users ) && in_array( $login, $allowed_users ) ) {
                return true;
            }
        }

        return $enable;
    }
    add_filter( 'wpcom_vip_qm_enable', 'vip_custom_enable_query_monitor' );
    ```

**Caution**

When enabling Query Monitor through code, avoid disabling access for VIP Support
users whose roles will appear as `vip_support`.

If the `wpcom_vip_qm_enable` filter returns `false` for users with the role `vip_support`,
VIP team members will not be able to use Query Monitor in a situation where support
is required. [This can delay VIP’s ability to promptly help](https://docs.wpvip.com/restricting-site-access/site-access-for-vip-support/)
especially during urgent or high-priority issues.

## Use Query Monitor when logged out

It is possible to view Query Monitor’s debugging output when not logged in, or when
logged in as a user without the `view_query_monitor` capability.

 1. Log in as a user with the `view_query_monitor` capability.
 2. Select the cogwheel icon in the upper right of Query Monitor’s console.
 3. Select the button labeled “**Set authentication cookie**“.
 4. Log out or switch users, then refresh the page.

Query Monitor’s console will be visible on both the front end and in the WordPress
Admin dashboard.

![Screenshot of the Query Monitor console with an arrow pointing to the cog icon
in the top right corner](https://docs.wpvip.com/wp-content/uploads/sites/2/2021/
10/image-16.png)

Example screenshot of the view of Query Monitor after selecting the cogwheel icon.

## Disable Query Monitor

To disable Query Monitor for an environment—including a local development environment—
define [the `QM_DISABLED` constant](https://querymonitor.com/help/configuration-constants/#qm-disabled)
as `true` in a file added to the [`client-mu-plugins` directory](https://docs.wpvip.com/wordpress-skeleton/client-mu-plugins-directory/).
[Environment-specific logic](https://docs.wpvip.com/infrastructure/environments/environment-specific-code/)
can be added to only define the constant for a specific environment type.

In this example code, the `QM_DISABLED` constant is defined as `true` only for an
application’s develop environment:

/client-mu-plugins/example-file.php

    ```lang-php
    if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && 'develop' === VIP_GO_APP_ENVIRONMENT ) {
        // Run this only on develop
    	if ( ! defined( 'QM_DISABLED' ) ) {
    		define( 'QM_DISABLED', true );
    	}
    } 
    ```

Last updated: August 04, 2025