Save WPForms Lite Entries in the Admin
Keeps a copy of every WPForms Lite submission in a private "Form Entries" list in the admin, since the free version does not store entries.
Opens WPIDE on
Code
add_action( 'init', function () {
register_post_type( 'wpide_wpf_entry', array(
'labels' => array( 'name' => 'Form Entries', 'singular_name' => 'Form Entry', 'menu_name' => 'Form Entries' ),
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-feedback',
'supports' => array( 'title', 'editor' ),
'capabilities' => array( 'create_posts' => 'do_not_allow' ),
'map_meta_cap' => true,
) );
} );
add_action( 'wpforms_process_complete', function ( $fields, $entry, $form_data ) {
$rows = array();
foreach ( (array) $fields as $field ) {
$rows[] = '<strong>' . esc_html( isset( $field['name'] ) ? $field['name'] : '' ) . ':</strong> ' . nl2br( esc_html( isset( $field['value'] ) ? (string) $field['value'] : '' ) );
}
$title = isset( $form_data['settings']['form_title'] ) ? $form_data['settings']['form_title'] : 'Form';
wp_insert_post( array(
'post_type' => 'wpide_wpf_entry',
'post_status' => 'private',
'post_title' => sprintf( '%s – %s', $title, wp_date( 'Y-m-d H:i' ) ),
'post_content' => wp_kses_post( implode( "<br>\n", $rows ) ),
'meta_input' => array( '_wpide_wpf_form_id' => (int) $form_data['id'] ),
) );
}, 10, 3 );
Notes
Entries are private posts visible to administrators only; WPForms Pro already stores entries, so skip this snippet there.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.