I’ve added a MailChimp API wrapper to v1.laddr.io since this is a common request, and created a commented-out example for the registration config file showing how someone could be added to a MailChimp list automatically after registering
You can find and open templates for all the files referenced below under the _parent
file tree and just hit save to create local copies that override the inherited templates.
Step 1: Configure MailChimp API key
Create the file php-config/RemoteSystems/MailChimp.config.php
and enter:
<?php
RemoteSystems\MailChimp::$apiKey = 'YOUR_API_KEY_HERE';
Replace YOUR_API_KEY_HERE with a MailChmip API. You can obtain one from the Extras > API Keys page under your account page on MailChimp’s website.
Step 2: Activate registration hook
Laddr v2.1.0 and older:
Assuming your laddr instance is up-to-date and someone has loaded your registration page recently, you’ll find the following sample within your _parent tree at php-config/Emergence/People/RegistrationRequestHandler.config.php
:
<?php
namespace Emergence\People;
#RegistrationRequestHandler::$onRegisterComplete = function(User $User, array $requestData) {
# // this hook is run after a new user acconut has been registered (the user is waiting though so keep things moving!)
#
# // add new user to a MailChimp list
# \RemoteSystems\MailChimp::call('lists/subscribe', [
# 'id' => 'YOUR_LIST_ID_HERE',
# 'email' => [
# 'email' => $User->Email
# ],
# 'merge_vars' => [
# 'FNAME' => $User->FirstName,
# 'LNAME' => $User->LastName
# ],
# 'double_optin' => false,
# 'replace_interests' => false,
# 'send_welcome' => false
# ]);
#};
Uncomment the commented-out block of code that creates a subscription in MailChimp. If you’re using the web-based IDE you can select the commented-out lines and press CMD+7 to uncomment them all. Be sure to replace YOUR_LIST_ID_HERE with the unique id for the list you want to subscribe users to automatically. It can be found on the MailChimp website under Settings > List name & defaults within the list page.
Laddr v2.2.0 and newer
You’ll find a similar block of code in event-handlers/Emergence/People/RegistrationRequestHandler/registerComplete/mailchimp.php
instead