# Paid Memberships Pro: Members per Level Dashboard Widget

> Adds a dashboard widget that lists your membership levels with the number of active members in each, cached so the dashboard stays fast.

- Type: PHP
- Runs: Run everywhere
- Category: [Memberships](https://wpide.com/library/category/memberships/)
- Tags: pmpro, dashboard, reporting
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/pmpro-members-by-level-widget/

## Code

```php
if ( ! function_exists( 'pmpro_getAllLevels' ) ) {
    return;
}

add_action( 'wp_dashboard_setup', function () {
    if ( ! current_user_can( 'pmpro_memberslist' ) && ! current_user_can( 'manage_options' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_pmpro_levels', 'Members per level', function () {
        global $wpdb;

        $counts = get_transient( 'wpide_pmpro_level_counts' );

        if ( false === $counts ) {
            $rows   = $wpdb->get_results( "SELECT membership_id, COUNT(DISTINCT user_id) AS total FROM {$wpdb->pmpro_memberships_users} WHERE status = 'active' GROUP BY membership_id" );
            $counts = wp_list_pluck( (array) $rows, 'total', 'membership_id' );
            set_transient( 'wpide_pmpro_level_counts', $counts, HOUR_IN_SECONDS );
        }

        echo '<table class="widefat striped"><thead><tr><th scope="col">Level</th><th scope="col">Active members</th></tr></thead><tbody>';

        foreach ( pmpro_getAllLevels( true ) as $level ) {
            printf( '<tr><td>%1$s</td><td>%2$s</td></tr>', esc_html( $level->name ), esc_html( number_format_i18n( (int) ( $counts[ $level->id ] ?? 0 ) ) ) );
        }

        echo '</tbody></table>';
        printf( '<p><a href="%s">View members</a></p>', esc_url( admin_url( 'admin.php?page=pmpro-memberslist' ) ) );
    } );
} );

add_action( 'pmpro_after_change_membership_level', function () {
    delete_transient( 'wpide_pmpro_level_counts' );
} );
```

## Notes

Counts refresh every hour and whenever a membership changes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Paid Memberships Pro: Members per Level Dashboard Widget" 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/
