To keep my site layout simple i want to hide the subscription block in case a user is already subscribed to my mailchimp newsletter.
what is the best practice to do that? is there an API call to achieve it or do i need to dig it out of the DB?


seanberto’s picture

Hi Bara,

I'll chat with Lev about this. Just to clarify, how would the user unsubscribe then? Via the user profile screen?


levelos’s picture

Status: Active » Closed (fixed)

There's an API call in the module, _mailchimp_is_subscribed(). Note that this pings MailChimp, so isn't particularly fast.

Anonymous’s picture

ping every time would be a bit intense. yes the user needs to go to his profile page or unsubscribe via newsletter link.

rickmanelius’s picture

Status: Closed (fixed) » Active

Hey Everyone,

I'm reopening this because merely having an API call is not front-end user solution. I actually had a client request this, so it's still a valid feature request.

Goal: A block visibility setting that could turn off this block if a user is already subscribed.

Questions 1: User profile updates
- Yes. I'd still like to keep the full subscription options in the user page (see comment #1). The block is more for getting new users to opt in. After that, seeing the block can get annoying. After all, how many times do you really need to update your preferences?
- Additionally, since this information is pulled from the mailchimp API and not stored in the local db, a person unsubscribing from the newsletter email itself would have their preferences respected.

Question 2: What about performance?
- Again, if the block already requires pinging mailchimp for a person's current subscription settings, it'll be no more difficult at hook_block to simply return null and move on.

Implementation would essentially be a system setting attached to the mailchimp block itself that would be a binary flag to do the above.

If it would get committed to the module, I'll gladly provide a patch.

levelos’s picture

Status: Active » Closed (won't fix)

Sorry rickman, but I don't feel an additional setting to hide blocks for given lists if a user is already is a broad enough use case to warrant inclusion in the module. There are many approaches you could take to solve this problem in your own code.

rickmanelius’s picture

I would disagree simply on the basis that one could see putting a 'subscribe to learn more' block on any content page in order to get the highest subscription rate... and then this very same block being repetitive to those already subscribed!

But, I'm not here to argue. I'll simply hack the mailchimp module block and do it that way.

seanberto’s picture

Hi Rickman,

Lev and I didn't mean to imply that your use case isn't valid, only that the settings form for the 6.x branch is already pretty cluttered with options and that this use case pry doesn't warrant adding that complexity to all users. Moreover, we are focused on the 7.x-2x branch of the module for new features, so it isn't something that we are interested in adding.

I think that it would be interesting for you to post your solution to this ticket for others that might want to handle this. I'm pretty sure that you could handle this with block visibility overrides, rather than hacking the module - which hopefully presents a more sustainable solution.

Thanks for the discussion and sharing your ideas/solutions!


patrickharris’s picture

H'mm - it's very unintuitive to have a block ask you to subscribe, when you already are. The only way of using the block as it currently is, seems to be to use it as a "subscribe any email to our Newsletter" block.

rickmanelius’s picture

Hi Seanberto,

Will definitely post my changes compared to the drupal 7 branch. And no offense taken! I know you guys have a ton going on. I just wanted to plead my case :)

I'll be working on this clients work this thursday, so I'll probably get a patch together by the weekend.

ryank76’s picture

Was there any progress? I agree with #8, it's weird to be shown a block if you're already subscribed.

A way to change the text if the user is subscribed would be an option.

ryank76’s picture

What about a block setting for

Show if the following PHP code returns TRUE

So it shows the block if the 'user is not subscribed' code returns TRUE. Is that possible? (Not a developer)

pierrot’s picture

I wrote this in block setting to avoid the block to be shown for subscribed users, except on their user profile :

global $user;

if (0 != $user->uid) {
	if (_mailchimp_is_subscribed('list_id', $user->mail, $q = NULL)){
		if (check_plain(arg(0))== 'user' && (check_plain(arg(1)) == $user->uid) ){
			return true;
			return false;
               return true;
       return true;

Hope this helps