Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/functions.php Secret
Created Apr 10, 2017

Embed
What would you like to do?
<?php
/**
* Integrate WPForms with ConvertKit
*
*/
function be_wpforms_send_data_to_convertkit( $fields, $entry, $form_data, $entry_id ) {
// Get API key and CK Form ID
$api_key = $ck_form_id = false;
if( !empty( $form_data['settings']['be_convertkit_api'] ) )
$api_key = esc_html( $form_data['settings']['be_convertkit_api'] );
if( !empty( $form_data['settings']['be_convertkit_form_id'] ) )
$ck_form_id = intval( $form_data['settings']['be_convertkit_form_id'] );
if( ! ( $api_key && $ck_form_id ) )
return;
// Get email and first name
$email_field_id = $form_data['settings']['be_convertkit_field_email'];
$first_name_field_id = $form_data['settings']['be_convertkit_field_first_name'];
$args = array(
'api_key' => $api_key,
'email' => $fields[$email_field_id]['value'],
'first_name' => $fields[$first_name_field_id]['value']
);
if( empty( $args['email'] ) || empty( $args['first_name'] ) )
return;
// Submit to ConvertKit
$request = wp_remote_post( add_query_arg( $args, 'https://api.convertkit.com/v3/forms/' . $ck_form_id . '/subscribe' ) );
// $response = json_decode( wp_remote_retrieve_body( $request ) );
// print_r( $response );
// exit;
}
add_action( 'wpforms_process_complete', 'be_wpforms_send_data_to_convertkit', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.