PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

mailchimp to s2member deletion

s2Member Plugin. A Membership plugin for WordPress®.

mailchimp to s2member deletion

Postby Leinad » June 24th, 2011, 8:52 pm

if you check

2) Wordpress admin - S2Member - API / List Servers – Automate Un-Subscribe/Opt-Outs

you can see there's an option named "process list removals automatically"

This options can control the sync from s2member to mailchimp. But I can't see options the other way around.

Say me, Daniel create an account in my site, it creates an s2member account and at the same time it adds me to mailchimp.
When the site sends a mail from mailchimp to all users, I'll get a message...and in the mail there's an "unsubscribe" link. When I click this it will delete me from the mailchimp list, but not my s2member user.

Is there ANY way to acomplish this? (delete my s2member account when I click the unsubscribe link)

thanks :)
User avatar
Leinad
Registered User
Registered User
 
Posts: 11
Joined: June 22, 2011

Re: mailchimp to s2member deletion

Postby BobTabor » June 24th, 2011, 10:20 pm

In short: I'm 99% sure s2Member doesn't support this today. (I hope I'm wrong ...)

**It IS possible** -- and if you needed this functionality, you may have to pay someone on Elance to code it. They will need this as a reference:

http://apidocs.mailchimp.com/webhooks/

The API supports a "call back" notification when events (like unsubscribes) occur, allowing you to do the look-up and removal. But there are challenges ... keeping user information in sync across two systems would be quite a task. I've done it, and it sucks. Having said that, if you figure out, I would be interested in it, too! Good luck!
User avatar
BobTabor
Experienced User
Experienced User
 
Posts: 84
Joined: April 28, 2011

Re: mailchimp to s2member deletion

Postby Leinad » June 25th, 2011, 11:32 am

ok, I just needed to know if it was possible, I'm a PHP coder but mailchimp is somewhat new to me, and I needed a pointer in the right direction.

Well, I'll try, then I'll let you know :P
User avatar
Leinad
Registered User
Registered User
 
Posts: 11
Joined: June 22, 2011

Re: mailchimp to s2member deletion

Postby Leinad » July 3rd, 2011, 4:55 pm

I was able to make it work...
this is the webhook file (which is called everytime a user unsubscribes in Mailchimp

Code: Select all
<?php

include("wp-config.php");

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);

foreach(
$_POST as $key => $value)
{
    if(is_array($value))
    {
        foreach($value as $keyValue => $val)
        {
            if($keyValue == "email")
            {
                $email = $val;
            }
        }
    }
}

$sql = "DELETE FROM wp_users  WHERE user_email = '$email'";
$query = mysql_query($sql);

?>
Last edited by Cristián Lávaque on July 3rd, 2011, 8:35 pm, edited 2 times in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
Leinad
Registered User
Registered User
 
Posts: 11
Joined: June 22, 2011

Re: mailchimp to s2member deletion

Postby BobTabor » July 3rd, 2011, 5:09 pm

AWESOME! Thanks for posting!

... and this would be a good code example for other notifications like 'email updates'.
User avatar
BobTabor
Experienced User
Experienced User
 
Posts: 84
Joined: April 28, 2011

Re: mailchimp to s2member deletion

Postby Cristián Lávaque » July 3rd, 2011, 8:38 pm

Thanks a lot for sharing that, Leinad. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: mailchimp to s2member deletion

Postby Jason Caldwell » July 4th, 2011, 12:42 pm

Thanks for sharing this. I'll see what we can do to support this in a future release of s2Member.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: mailchimp to s2member deletion

Postby Leinad » July 5th, 2011, 4:52 pm

I have finished the mailchimp to s2member integration.

I needed to create 2 different webhooks. Heres the code.

Code: Select all
<?php

//this one only updates the email, you need to create a webhook that only triggers on "mail changed"
include("wp-config.php");

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);

$stringData .= $sql = "UPDATE wp_users SET user_email = '".$_POST["data"]["new_email"]."' WHERE user_email = '".$_POST["data"]["old_email"]."'";
$query = mysql_query($sql);

?>


and
Code: Select all
<?php

//this one is more tricky hehe, it updates all the data, but as I'm using several custom fields the code added up! Is the same principle, though.

include("wp-config.php");

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);

//select user with the email that matches the notice from mailchimp
$sql = "SELECT * FROM wp_users WHERE user_email = '".$_POST["data"]["email"]."'";
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);

//update first name
$sql = "SELECT umeta_id FROM wp_usermeta WHERE user_id = ".$row["ID"]." AND meta_key = 'first_name'";
$query = mysql_query($sql);
$umetaId = mysql_result($query, 0);

$stringData .= $sql = "UPDATE wp_usermeta 
                SET 
                    meta_value = '"
.$_POST["data"]["merges"]["MERGE1"]."' 
                WHERE umeta_id = '"
.$umetaId."'";
$query = mysql_query($sql);

//update last name
$sql = "SELECT umeta_id FROM wp_usermeta WHERE user_id = ".$row["ID"]." AND meta_key = 'last_name'";
$query = mysql_query($sql);
$umetaId = mysql_result($query, 0);

$stringData .= $sql = "UPDATE wp_usermeta 
                SET 
                    meta_value = '"
.$_POST["data"]["merges"]["MERGE2"]."' 
                WHERE umeta_id = '"
.$umetaId."'";
$query = mysql_query($sql);

//select the metadata (in my case I'm using a lot of merge fields)
$sql = "SELECT * FROM wp_usermeta WHERE user_id = ".$row["ID"]." AND meta_key = 'wp_s2member_custom_fields'";
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);

$data["merge3"] = $_POST["data"]["merges"]["MERGE3"];
$data["merge4"] = $_POST["data"]["merges"]["MERGE4"];
$data["merge10"] = $_POST["data"]["merges"]["MERGE10"];
$data["merge5"] = $_POST["data"]["merges"]["MMERGE5"];
$data["merge6"] = $_POST["data"]["merges"]["MMERGE6"];
$data["merge7"] = $_POST["data"]["merges"]["MMERGE7"];
$data["merge8"] = $_POST["data"]["merges"]["MMERGE8"];
$data["merge9"] = $_POST["data"]["merges"]["MERGE9"];
$data["merge13"] = $_POST["data"]["merges"]["MMERGE13"];

$data = serialize($data);

//update that particular meta row
$stringData .= $sql = "UPDATE wp_usermeta 
                SET 
                    meta_value = '"
.$data."' 
                WHERE umeta_id = '"
.$row["umeta_id"]."'";
$query = mysql_query($sql);

?>


I'm still missing the integration from s2member to mailchimp. Can you point me in the right direction? I really don't want to search through the entire code :(
User avatar
Leinad
Registered User
Registered User
 
Posts: 11
Joined: June 22, 2011


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron