• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Store
    • Cart
    • Checkout
  • Blog
    • Basics [Free]
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Contact
  • Sign In
  • Show Search
Hide Search
Home » Actions » Simple MailChimp integration

Simple MailChimp integration

Chad Butler · Mar 28, 2012 ·

Note: this example predates the introduction of the MailChimp Integration extension. I recommend that you use that extension instead as it is far easier to use and also utilizes the latest MailChimp API (version 3.0).

Here is an example of a simple integrating MailChimp with the WP-Members registration process.  This could be modified to suit similar integrations as long as there is an API to hook into.

This article is only available to WP-Members Support Subscribers. If you have an existing subscription, please login below. If you do not have a current support subscription, you can purchase a support subscription here.

Already a Member? Log In Here
   
Forgot password? Click here to reset

To gain full access to WP-Members premium content, a current support subscription is required. You can purchase an annual support subscription for as little as $59, which provides you with access to priority support, a customer support forum, access to code snippets, and more.

Why wait? Choose your subscription option here.

[
Why join?]

Actions, Tips and Tricks actions, email, integration, mailchimp, tips, wpmem_post_register_data

Welcome to RocketGeek Interactive › Forums › Simple MailChimp integration

Tagged: actions, email, integration, mailchimp, tips, wpmem_post_register_data

  • This topic has 7 replies, 2 voices, and was last updated 8 years, 5 months ago by Chad Butler.
Viewing 7 reply threads
  • Author
    Posts
    • May 4, 2012 at 1:09 pm #528
      Chad Butler
      Keymaster

      Here is an example of a simple integrating MailChimp with the WP-Members registration process.  This could be modified to suit similar integrations as
      [See the full post at: Simple MailChimp integration]

    • September 4, 2012 at 10:00 am #1196
      ajs
      Participant

      Great tip, Chad. I am going to create a version of this for “wpmem_mailchimp_opt-out” so that I can default people to being subscribed to a list. Or, perhaps, change this to support opt-in/out of more than one list based on multiple values of $fields[] related to each list.

    • September 4, 2012 at 10:24 am #1197
      Chad Butler
      Keymaster

      Yes, there are quite a few spin-offs of this. Thanks for sharing your ideas.

    • September 7, 2012 at 7:19 pm #1272
      ajs
      Participant

      Using the example above, it does not appear that FNAME or LNAME are ever populated and passed to Mailchimp. Looking into wp-members-register.php, it does not appear that $fields, which is passed to the wpmem_post_register_data action, contains first_name or last_name. The values for first_name and last_name appear to be in wp_usermeta as opposed to wp_user. Perhaps modifying wp-members-register.php to pass some or all of usermeta as values of $fields or adding a call to get_user_meta( $fields[‘ID’] ) within the action would work. I’ll probably try the latter but I am also playing with a modification to AutoChimp to hook in with WP-Members.

    • September 8, 2012 at 8:42 am #1273
      Chad Butler
      Keymaster

      First the general answer…

      The $fields array is actually quite dependent on what fields you actually have in your registration form, plus the registration timestamp, their IP address, the URL they registered on, and the ID.

      If you want to see what is actually being passed through the process, you can trap it in the process by starting your action hook function with:

      echo “<pre>”; print_r( $fields ); exit();

      That will print out the array values and stop the function so you can see them.

      In a default and unmodified install, first name/last name will be there.

      Now, because I know a little bit about your specific situation, I believe you are using one of the processes that builds a dropdown list of names to use in the form:

      https://rocketgeek.com/filter-hooks/add-a-database-generated-list-of-values-to-the-registration-form/
      https://rocketgeek.com/filter-hooks/add-a-database-generated-list-of-values-to-the-registration-form-as-username/

      That is important because both of those examples get their first name/last name individual values (not the full name) during the wpmem_post_register_action and not during the registration process.  The reason for this is that you need to know what value the user selected from the dropdown before you know what the individual components are.  So in that case, $fields would not carry those array values like it would if first name and last name were in the registration form.

      So, how would you pick those up for MailChimp?

      First, it is important to point out that both the MailChimp process and part of the dropdown list registration example use the same action: wpmem_post_register_data.  Can you have more than one function that hooks in here? Yes, but you have to be cautious in doing that because the order in which they are fired is important – one needs data from the other.

      In my opinion, it would be better to merge your two processes into one function so that you can get the steps in order.  That would involve doing the dropdown data management first, followed by the MailChimp process.

      If you do that, you have the added advantage of not needing to do anything additional to pick up first name and last name since that process is part of the other function.  So you would be able to use $name[‘first_name’] and $name[‘last_name’] for your name values rather than have to query the database using get_user_meta.

      (You would need to make sure that in putting these two processes together in one function that you take the “return;” out of the end of the first process.  That should go without saying and I know you know that – this statement is more for anyone else who comes along that is more at the cut-and-paste level of php and wouldn’t necessarily know to do that.)

      Hope that helps!

    • September 8, 2012 at 8:48 am #1274
      Chad Butler
      Keymaster

      Another possibility might be to call the MailChimp function from the update_my_db_table function in the other process rather than using the action hook.  You would just need to adjust what is being passed to the function and how so that it has the elements it needs to complete.

    • September 8, 2012 at 9:02 am #1275
      ajs
      Participant

      Thanks. Yes, I forgot to take into account when first_name and last_name were being populated in my specific case.

      I want to stop the MailChimp subscription (and subsequent Confirmation and Welcome) messages from going to the user until after registration moderation is complete, i.e., an admin has manually activated the user. It seems like AutoChimp works this way.

      Autochimp has integration with some other plugins, e.g., BuddyPress, Reg Plus and Plus Redux, so I’ve been looking at the plugin code to see how difficult it would be for me to modify it to work with my setup. My guess is that it would work with WP-Members [1], out of the box, using standard fields in forms and populating them normally but, like the script above, it can’t get the names when it needs them without modification.

      Today’s project is to get this working, one way or the other.

      [1] It wouldn’t be able to find custom fields, in the usermeta table, or elsewhere, and map them to MailChimp tags, either. So, a WP-Members integration for AC has some value (to me.) There was some talk by the developer of what sounded like a generic extension to pull and map fields from usermeta regardless of using any other registration system but that does not seem to be happening soon.

    • September 8, 2012 at 12:37 pm #1276
      Chad Butler
      Keymaster

      Definitely some interesting ideas. While I’m usually opposed to approaching integration with specific plugins, AutoChimp would be one that would be an exception to that rule since there is a fairly large audience for that.

      Since my initial approach to almost everything is to start with “is there a hook for that?” that makes evident that (1) there are no hooks in the user activation process and (2) this would be a good reason to add one.

      That would allow an admin to accept the user’s subscribe request at registration, but not submit it to the API until the moderation process is run and the user is approved.

      I do have an update scheduled for Monday evening (version 2.7.7, currently a beta release), so I’ll look into this some more and maybe slip another hook in there.

  • Author
    Posts
Viewing 7 reply threads
  • You must be logged in to reply to this topic.
Log In

Ready to get started?

Join Today!

© 2021 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Refund Policy