latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

My MailChimp Integration: Daily Email Digest

Home Forums Community Forum My MailChimp Integration: Daily Email Digest

This topic contains 0 replies, has 1 voice. Last updated by  Sacha Greif 4 years, 6 months ago.

Topic Author Topic
Posted: Wednesday Jun 27th, 2012 at 12:00 am #17615
Sacha Greif
Username: sachag

I just spent a day working on integrating my S2Member site with MailChimp, and I wanted to share what I did in hope it helps others.

What I needed was a way to let members know when I added new content (in this case, videos) on the site, with a daily email digest summarizing all the new content posted in the last day. I tried plugins like Subscribe2, but they’re clunky and inflexible. What’s more, they sent the same notification to everybody regardless of subscription level. Thankfully MailChimp is much more powerful and can help us do all of that. Here’s what I did:

1. First I used the S2Member List API to automatically subscribe new members to a MailChimp list, in three different groups according to their membership level (that being said, there are a lot of other plugins to subscribe WP users to MailChimp lists).

2. I then created three RSS Campaigns in MailChimp. Those campaigns subscribe to a RSS feed and auto-send a daily, weekly, or monthly email digest whenever it detects new content. You get a couple template tags that are replaced by the dynamically generated RSS content, otherwise you can use any MailChimp template (or create your own).

3. I know needed the three appropriate RSS feeds. The RSS feed for the highest access level was easy, since these members have access to the whole site. So I simply used WordPress’ built-in custom post type feeds, like this:

http://mysite.com/feed/?post_type=your_custom_post_type

The problem was for the other two levels. Level 1 member have access to free videos, plus level 1 videos. While Level 2 members have access to free, Level 1, and Level 2 videos. So I needed to build custom feeds.

I tried many solutions to merge the feeds, including Yahoo Pipes (http://pipes.yahoo.com), but in the end decided to combine the feeds from within WordPress instead. Here’s what that code looks like:

function videos_custom_feed_rss2() {
	global $wp;
	if(isset($_GET["custom_feed"])){
		$feed=$_GET["custom_feed"];
		$args=array();
		$taxonomies="free_videos";
		switch ($feed) {
			case 'level_1':
				$taxonomies.=", level_1";
				break;
			case 'level_2':
				$taxonomies.=", level_1, level_2";
				break;
			default:
				break;
		}
		$args = array(
			'post_type'=> 'woo_video',
			'woo_video_category' => $taxonomies,
			'posts_per_page'=>30,
			'orderby'=>date,
			'order'=>DESC
		);
		$custom_query=query_posts($args);
	}
	do_feed_rss2( false ); // Call default function
}
remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'videos_custom_feed_rss2', 10, 1 );

And I can now access my custom feeds at

http://mysite.com/feed/?custom_feed=level1

and

http://mysite.com/feed/?custom_feed=level2

4. As a bonus, I also used a custom function based on this plugin to extract the video thumbnail for each post and add it to the RSS feed as an RSS enclosure.

So now I have automatic email digests that go out daily only to the appropriate members, include images and a nice template, and have stats on top of that thanks to MailChimp!

That’s it, hope this helps somebody :)

  • This topic was modified 4 years, 6 months ago by  Sacha Greif.
  • This topic was modified 3 years, 4 months ago by  Sacha Greif.

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.