# "Download My Data" Request Button

> Adds a [wpide_export_data] shortcode with a button that asks WordPress's privacy tools to prepare a copy of the member's personal data, confirmed by email.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: privacy, account, gdpr
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/personal-data-export-button/

## Code

```php
add_action( 'template_redirect', function () {
    if ( empty( $_POST['wpide_export_nonce'] ) || ! is_user_logged_in() ) {
        return;
    }

    if ( ! wp_verify_nonce( sanitize_key( $_POST['wpide_export_nonce'] ), 'wpide_export_request' ) ) {
        wp_die( 'The form expired. Please go back and try again.' );
    }

    $request_id = wp_create_user_request( wp_get_current_user()->user_email, 'export_personal_data' );

    if ( is_wp_error( $request_id ) ) {
        $state = 'duplicate_request' === $request_id->get_error_code() ? 'pending' : 'error';
    } else {
        wp_send_user_request( $request_id );
        $state = 'sent';
    }

    wp_safe_redirect( add_query_arg( 'export-request', $state ) );
    exit;
} );

add_shortcode( 'wpide_export_data', function () {
    if ( ! is_user_logged_in() ) {
        return '';
    }

    $messages = array(
        'sent'    => 'Check your email to confirm the request. We will send your data once it is ready.',
        'pending' => 'You already asked for a copy of your data. Check your email for the confirmation link.',
        'error'   => 'Something went wrong. Please contact us for a copy of your data.',
    );
    $state = isset( $_GET['export-request'] ) ? sanitize_key( $_GET['export-request'] ) : '';

    if ( isset( $messages[ $state ] ) ) {
        return '<p class="wpide-export-notice" role="status">' . esc_html( $messages[ $state ] ) . '</p>';
    }

    return '<form method="post" class="wpide-export-form">'
        . wp_nonce_field( 'wpide_export_request', 'wpide_export_nonce', true, false )
        . '<p><button type="submit">Request a copy of my data</button></p></form>';
} );
```

## Notes

You send the export from Tools > Export Personal Data, or let WordPress email it once you approve the request.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Download My Data" Request Button" 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/
