yikes-mailchimp-before-submission doesn’t works
-
i created this function because the form is updating the merge variable if member exist
i want to serach contact in list and if is exist do not update the MMERGE9 variablethe search function is working but even if contact exist the value returned is the value of mmerge-9 on the form
add_filter( ‘yikes-mailchimp-before-submission-1’ , ‘do_not_update_source’ );
function do_not_update_source($user_data) {
$api_key = ‘my API Key’;
$testnews=’y list id’;//
$dc = substr($api_key,strpos($api_key,’-‘)+1); // us5, us8 etc
$datasearch = array();
$membernews=searchmember($datasearch, md5($user_data[‘EMAIL’]),$testnews);
if(md5($user_data[‘EMAIL’])== $membernews->id){
$exist=” existe”;
$user_data[‘MMERGE9’]=$membernews->merge_fields->MMERGE9;}
else {
$exist=” n’existe pas”;
$user_data[‘MMERGE9′] =’newsletter article site’;
}return $user_data ;
}
function rudr_mailchimp_curl_connect( $url, $request_type, $api_key, $data = array() ) {
$mch = curl_init();
if( $request_type == ‘GET’ )
{$url .= ‘?’ . http_build_query($data);}
if( $request_type == ‘POST’ ) {
curl_setopt($mch, CURLOPT_POST, true);
//curl_setopt($mch, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json
}
if( $request_type == ‘PATCH’ ) {
curl_setopt($mch, CURLOPT_POST, true);
curl_setopt($mch, CURLOPT_CUSTOMREQUEST, “PATCH”);
curl_setopt($mch, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json
}
if( $request_type == ‘PUT’ ) {
curl_setopt($mch, CURLOPT_POST, true);curl_setopt($mch, CURLOPT_CUSTOMREQUEST, “PUT”);
curl_setopt($mch, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json
}
if( $request_type == ‘DELETE’ ) {
curl_setopt($mch, CURLOPT_POST, true);
curl_setopt($mch, CURLOPT_CUSTOMREQUEST, “DELETE”);
curl_setopt($mch, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json
}$headers = array(
‘Content-Type: application/json’,
‘Authorization: Basic ‘.base64_encode( ‘user:’. $api_key )
);
curl_setopt($mch, CURLOPT_URL, $url );
curl_setopt($mch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($mch, CURLOPT_USERAGENT, ‘PHP-MCAPI/2.0’);
curl_setopt($mch, CURLOPT_RETURNTRANSFER, true); // do not echo the result, write it into variable
curl_setopt($mch, CURLOPT_CUSTOMREQUEST, $request_type); // according to MailChimp API: POST/GET/PATCH/PUT/DELETE
curl_setopt($mch, CURLOPT_TIMEOUT, 360000 );
curl_setopt($mch, CURLOPT_SSL_VERIFYPEER, false); // certificate verification for TLS/SSL connection
curl_setopt($mch, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json
return curl_exec($mch);
}function searchmember($data, $memberid, $list)
{ $api_key = ‘my API KEY’;
$dc = substr($api_key,strpos($api_key,’-‘)+1);
$datasearch = $data;
// URL to connect
$urlsearch=’https://’.$dc.’.api.mailchimp.com/3.0/lists/’.$list.’/members/’.$memberid.”;
$bodysearch = json_decode( rudr_mailchimp_curl_connect( $urlsearch, ‘GET’, $api_key, $datasearch ) );
return $bodysearch;
}
- The topic ‘yikes-mailchimp-before-submission doesn’t works’ is closed to new replies.