get_kit_option( 'liquid_mailchimp_api_key' ); if( empty( $api_key ) || strpos( $api_key, '-' ) === false ) { wp_die( liquid_helper()->get_kit_option( 'liquid_mailchimp_text__missing_api' ) ); } $MailChimp = new \liquid_MailChimp( $api_key ); $list_id = $_POST['list_id']; $email = isset( $_POST['email'] ) ? sanitize_email( $_POST['email'] ) : ''; $fname = isset( $_POST['fname'] ) ? sanitize_text_field( $_POST['fname'] ) : ''; $lname = isset( $_POST['lname'] ) ? sanitize_text_field( $_POST['lname'] ) : ''; $use_opt_in = isset( $_POST['use_opt_in'] ) ? sanitize_text_field( $_POST['use_opt_in'] ) : ''; $tags = isset( $_POST['tags'] ) ? explode( ',', sanitize_text_field( $_POST['tags'] ) ) : array(); if( empty( $list_id ) ) { wp_die( liquid_helper()->get_kit_option( 'liquid_mailchimp_text__missing_list' ) ); } $result = $MailChimp->post( "lists/$list_id/members", array( 'email_address' => $email, 'merge_fields' => array( 'FNAME'=> $fname, 'LNAME' => $lname ), 'status' => ($use_opt_in == 'yes' ? 'pending' : 'subscribed'), 'tags' => $tags, ) ); if ( $MailChimp->success() ) { // Success message echo liquid_helper()->get_kit_option( 'liquid_mailchimp_text__thanks' ); } else { // Display error echo $MailChimp->getLastError(); } if ( !$MailChimp->getLastError() && isset(json_decode( wp_remote_retrieve_body( $MailChimp->getLastResponse() ), true )['detail']) ){ switch ( json_decode( wp_remote_retrieve_body( $MailChimp->getLastResponse() ), true )['title'] ) { case 'Member Exists' : printf( '