Community Support Forums — WordPress® ( Users Helping Users ) — 2011-07-05T16:52:05-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=10289 2011-07-05T16:52:05-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=22427#p22427 <![CDATA[Re: mailchimp to s2member deletion]]>
I needed to create 2 different webhooks. Heres the code.

Code:
<?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:
<?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 :(

Statistics: Posted by Leinad — July 5th, 2011, 4:52 pm


]]>
2011-07-04T12:42:43-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=22294#p22294 <![CDATA[Re: mailchimp to s2member deletion]]> Statistics: Posted by Jason Caldwell — July 4th, 2011, 12:42 pm


]]>
2011-07-03T20:38:02-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=22226#p22226 <![CDATA[Re: mailchimp to s2member deletion]]>

Statistics: Posted by Cristián Lávaque — July 3rd, 2011, 8:38 pm


]]>
2011-07-03T17:09:58-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=22204#p22204 <![CDATA[Re: mailchimp to s2member deletion]]>
... and this would be a good code example for other notifications like 'email updates'.

Statistics: Posted by BobTabor — July 3rd, 2011, 5:09 pm


]]>
2011-07-03T16:55:20-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=22202#p22202 <![CDATA[Re: mailchimp to s2member deletion]]> this is the webhook file (which is called everytime a user unsubscribes in Mailchimp

Code:
<?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);

?>

Statistics: Posted by Leinad — July 3rd, 2011, 4:55 pm


]]>
2011-06-25T11:32:20-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=21694#p21694 <![CDATA[Re: mailchimp to s2member deletion]]>
Well, I'll try, then I'll let you know :P

Statistics: Posted by Leinad — June 25th, 2011, 11:32 am


]]>
2011-06-24T22:20:07-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=21659#p21659 <![CDATA[Re: mailchimp to s2member deletion]]>
**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!

Statistics: Posted by BobTabor — June 24th, 2011, 10:20 pm


]]>
2011-06-24T20:52:50-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10289&p=21656#p21656 <![CDATA[mailchimp to s2member deletion]]>
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 :)

Statistics: Posted by Leinad — June 24th, 2011, 8:52 pm


]]>