• Resolved taieb

    (@taieb)


    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 variable

    the 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;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @taieb,

    Nice work. I think the problem is that our filter name has changed from yikes-mailchimp-before-submission to yikes-mailchimp-filter-before-submission.

    Can you try your same code with the new filter (yikes-mailchimp-filter-before-submission-1 for form ID `).

    At one point we had actions and filters both named yikes-mailchimp-before-submission and we changed the filters to yikes-mailchimp-filter-before-submission.

    Sorry about that!

    Let me know whether that works.

    Cheers,
    Kevin.

    Thread Starter taieb

    (@taieb)

    Hello Kevin,
    that works thank you for hellp.
    Cheers,
    Taieb

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Awesome! Let me know if you need any more help extending the plugin. I’m always interested in how developers extend our plugin.

    Thread Starter taieb

    (@taieb)

    Hello just for information the plugin is updating the timestamp_opt if member exists on list

    so i commented //’timestamp_opt’ => current_time( ‘Y-m-d H:i:s’, 1 ),
    in process_form_submission_ajax.php and process_form_submission.php
    // This is the array we’re going to pass through to the Mailchimp API
    $member_data = array(
    ’email_address’ => $sanitized_email,
    ‘merge_fields’ => $merge_variables,
    //’timestamp_opt’ => current_time( ‘Y-m-d H:i:s’, 1 ),
    );
    Cheers,
    Taieb

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘yikes-mailchimp-before-submission doesn’t works’ is closed to new replies.