# Pending Privacy Requests Badge in the Admin Menu

> Shows a count bubble next to Tools and the Export and Erase Personal Data menu items when confirmed privacy requests are waiting for you to process them.

- Type: PHP
- Runs: Admin only
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: gdpr, admin-menu, notifications
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-requests-menu-badge/

## Code

```php
add_action( 'admin_menu', function () {
    global $menu, $submenu, $wpdb;

    if ( ! current_user_can( 'export_others_personal_data' ) && ! current_user_can( 'erase_others_personal_data' ) ) {
        return;
    }

    $counts = get_transient( 'wpide_privacy_request_counts' );

    if ( false === $counts ) {
        $counts = array( 'export_personal_data' => 0, 'remove_personal_data' => 0 );
        $rows   = $wpdb->get_results( "SELECT post_name, COUNT(*) AS total FROM {$wpdb->posts} WHERE post_type = 'user_request' AND post_status = 'request-confirmed' GROUP BY post_name" );
        foreach ( $rows as $row ) {
            $counts[ $row->post_name ] = (int) $row->total;
        }
        set_transient( 'wpide_privacy_request_counts', $counts, 10 * MINUTE_IN_SECONDS );
    }

    $bubble = function ( $count ) {
        return $count ? ' <span class="awaiting-mod"><span class="pending-count">' . (int) $count . '</span></span>' : '';
    };
    $total = array_sum( $counts );

    if ( ! $total || empty( $submenu['tools.php'] ) ) {
        return;
    }

    foreach ( $submenu['tools.php'] as &$item ) {
        if ( 'export-personal-data.php' === $item[2] ) {
            $item[0] .= $bubble( $counts['export_personal_data'] );
        } elseif ( 'erase-personal-data.php' === $item[2] ) {
            $item[0] .= $bubble( $counts['remove_personal_data'] );
        }
    }
    unset( $item );

    foreach ( (array) $menu as $key => $item ) {
        if ( isset( $item[2] ) && 'tools.php' === $item[2] ) {
            $menu[ $key ][0] .= $bubble( $total );
        }
    }
}, 99 );

add_action( 'user_request_action_confirmed', function () {
    delete_transient( 'wpide_privacy_request_counts' );
} );
add_action( 'transition_post_status', function ( $new, $old, $post ) {
    if ( 'user_request' === $post->post_type ) {
        delete_transient( 'wpide_privacy_request_counts' );
    }
}, 10, 3 );
```

## Notes

Only confirmed requests are counted, since those are the ones that need action from you.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Pending Privacy Requests Badge in the Admin Menu" 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/
