Created
November 16, 2014 18:01
-
-
Save kasparsd/8580b4c109c118eb85a9 to your computer and use it in GitHub Desktop.
Capture form submissions from Contact Form 7 plugin for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wpcf7_before_send_mail', 'capture_entry' ); | |
function capture_entry( $cf7 ) { | |
$posted_fields = array(); | |
$submission = WPCF7_Submission::get_instance(); | |
$posted_data_raw = $submission->get_posted_data(); | |
// Extract field values. Be sure to take care of fields with multiple values! | |
foreach ( $posted_data_raw as $field_key => $field_value ) | |
if ( ! preg_match( '/^(_wpnonce|_wpcf7)/i', $field_key ) ) | |
$posted_fields[ $field_key ] = $field_value; | |
// Update post title and body content | |
wp_insert_post( array( | |
'post_type' => 'your-post-type', | |
'post_status' => 'draft', | |
'post_parent' => $cf7->id(), | |
'post_title' => $posted_fields['your-name'], // use any field or combination of fields | |
'post_content' => $posted_fields['your-message'] // use any field or combination of fields | |
) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment