# Save Contact Form 7 Submissions in the Admin

> Keeps a copy of every Contact Form 7 message in a private "Form Messages" list in the admin, so nothing is lost when an email goes missing.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, entries, storage
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-save-submissions/

## Code

```php
add_action( 'init', function () {
    register_post_type( 'wpide_cf7_message', array(
        'labels'          => array( 'name' => 'Form Messages', 'singular_name' => 'Form Message', 'menu_name' => 'Form Messages' ),
        'public'          => false,
        'show_ui'         => true,
        'show_in_menu'    => true,
        'menu_icon'       => 'dashicons-email-alt',
        'supports'        => array( 'title', 'editor' ),
        'capability_type' => 'post',
        'capabilities'    => array( 'create_posts' => 'do_not_allow' ),
        'map_meta_cap'    => true,
    ) );
} );

add_action( 'wpcf7_mail_sent', function ( $contact_form ) {
    $submission = class_exists( 'WPCF7_Submission' ) ? WPCF7_Submission::get_instance() : null;

    if ( ! $submission ) {
        return;
    }

    $lines = array();
    foreach ( (array) $submission->get_posted_data() as $key => $value ) {
        if ( 0 === strpos( $key, '_' ) ) {
            continue;
        }
        $lines[] = '<strong>' . esc_html( $key ) . ':</strong> ' . nl2br( esc_html( is_array( $value ) ? implode( ', ', $value ) : (string) $value ) );
    }
    $lines[] = '<strong>Page:</strong> ' . esc_url( (string) $submission->get_meta( 'url' ) );

    wp_insert_post( array(
        'post_type'    => 'wpide_cf7_message',
        'post_status'  => 'private',
        'post_title'   => sprintf( '%s – %s', $contact_form->title(), wp_date( 'Y-m-d H:i' ) ),
        'post_content' => wp_kses_post( implode( "<br>\n", $lines ) ),
        'meta_input'   => array( '_wpide_cf7_form_id' => (int) $contact_form->id() ),
    ) );
} );
```

## Notes

Messages are stored as private posts that only administrators can see (file uploads are not kept), so delete old ones from the list from time to time.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Save Contact Form 7 Submissions in the Admin" 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/
