# Export Network Users to CSV

> Adds an "Export CSV" button to Network Admin > Users that downloads every network user with their email, registration date, number of sites and super admin status.

- Type: PHP
- Runs: Admin only
- Category: [Multisite](https://wpide.com/library/category/multisite/)
- Tags: network-admin, users, export
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/ms-network-users-csv-export/

## Code

```php
if ( ! is_multisite() ) {
    return;
}

add_action( 'network_admin_notices', function () {
    $screen = get_current_screen();

    if ( ! $screen || 'users-network' !== $screen->id || ! current_user_can( 'manage_network_users' ) ) {
        return;
    }

    printf(
        '<div class="notice notice-info"><p><a class="button" href="%1$s">%2$s</a></p></div>',
        esc_url( wp_nonce_url( network_admin_url( 'edit.php?action=wpide_export_users' ), 'wpide_export_users' ) ),
        esc_html__( 'Export all users as CSV' )
    );
} );

add_action( 'network_admin_edit_wpide_export_users', function () {
    check_admin_referer( 'wpide_export_users' );

    if ( ! current_user_can( 'manage_network_users' ) ) {
        wp_die( esc_html__( 'Sorry, you are not allowed to export users.' ), 403 );
    }

    nocache_headers();
    header( 'Content-Type: text/csv; charset=utf-8' );
    header( 'Content-Disposition: attachment; filename=network-users-' . gmdate( 'Y-m-d' ) . '.csv' );

    $out    = fopen( 'php://output', 'w' );
    $supers = get_super_admins();
    fputcsv( $out, array( 'ID', 'Username', 'Email', 'Display name', 'Registered', 'Sites', 'Super admin' ) );

    $paged = 1;
    do {
        $users = get_users( array( 'blog_id' => 0, 'number' => 500, 'paged' => $paged, 'orderby' => 'ID', 'fields' => array( 'ID', 'user_login', 'user_email', 'display_name', 'user_registered' ) ) );
        foreach ( $users as $user ) {
            $row = array( $user->ID, $user->user_login, $user->user_email, $user->display_name, $user->user_registered, count( get_blogs_of_user( $user->ID ) ), in_array( $user->user_login, $supers, true ) ? 'yes' : 'no' );
            fputcsv( $out, array_map( function ( $cell ) {
                $cell = (string) $cell;
                return preg_match( '/^[=+\-@]/', $cell ) ? "'" . $cell : $cell; // Avoid spreadsheet formula injection.
            }, $row ) );
        }
        $paged++;
    } while ( count( $users ) === 500 );

    fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions
    exit;
} );
```

## Notes

Protected by a nonce and the manage_network_users capability. Very large networks are exported in batches of 500 users to keep memory low.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Export Network Users to CSV" 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/
