# Third-Party Requests Inspector in the Admin Bar

> Adds an admin bar item on the front of the site that counts the external domains the current page loads files from, and lists them on click, to help you keep your cookie notice and privacy policy accurate.

- Type: PHP
- Runs: Frontend only
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: admin-bar, audit, third-party
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-third-party-inspector/

## Code

```php
add_action( 'admin_bar_menu', function ( $bar ) {
    if ( is_admin() || ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $bar->add_node( array(
        'id'    => 'wpide-third-parties',
        'title' => 'Third parties: ...',
        'href'  => '#',
    ) );
}, 95 );

add_action( 'wp_footer', function () {
    if ( ! is_admin_bar_showing() || ! current_user_can( 'manage_options' ) ) {
        return;
    }
    ?>
<script>
(function () {
    var link = document.querySelector('#wp-admin-bar-wpide-third-parties > a');
    if (!link || !window.performance || !performance.getEntriesByType) { return; }
    function hosts() {
        var own = location.hostname, map = {};
        performance.getEntriesByType('resource').forEach(function (r) {
            var h;
            try { h = new URL(r.name).hostname; } catch (e) { return; }
            if (h && h !== own) { map[h] = (map[h] || 0) + 1; }
        });
        return map;
    }
    function label() { link.textContent = 'Third parties: ' + Object.keys(hosts()).length; }
    window.addEventListener('load', function () { setTimeout(label, 1500); });
    link.addEventListener('click', function (e) {
        e.preventDefault();
        var map = hosts();
        label();
        var lines = Object.keys(map).sort().map(function (h) { return h + ' (' + map[h] + ' requests)'; });
        window.alert(lines.length ? 'This page loaded files from:\n\n' + lines.join('\n') : 'This page loaded nothing from other domains.');
    });
})();
</script>
    <?php
}, 99 );
```

## Notes

Uses the browser's resource timing list, so requests made after the click are not counted until you click again.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Third-Party Requests Inspector in the Admin Bar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
