BuddyDev

Add Email Notification Unsubscribe Link to all BuddyPress Emails

BuddyPress allows users to unsubscribe from email notifications without logging in to the site.  The unsubscribe link is part of the email header(allows your email clients to attempt unsubscribe) and in the footer of the html email as shown below.

The Unsubscribe link is not visible to the users when using BuddyPress email in plaintext mode.

There are times when you may want to enable the unsubscibe link under content. For example

  • If you are not using BuddyPress html email, you can add the unsubscribe link at the bottom of the email.
  • Or you are using BuddyPress html email but want the link to be more prominent part of the content.

How do we filter the BuddyPress email content:-

There are two types of BuddyPress email content possible

  • html
  • and plaintext

BuddyPress provides us with a filter for each of the content type to filter the email content globally.

  • bp_email_get_content_html :- To filter the content for html email.
  • bp_email_get_content_plaintext :- To filter the content for plain text email.

If you are searching for the filter in your IDE, It is in “BP_Email” class and you should search for the dynamic filter bp_email_get_{$property_name}.

Since both the filter offers same data, we can write a simple function to filter the content and based on the content type(html/plaintext) add appropriate tag. The filter provides four arguments but we are only interested in the content and content type here, so I will only use these two.

As shown in the code, if the content type is html, we add a paragraph and an anchor element but if the content type is plaintext, we simply add text url.

Now, we need to add the filters.

To enable for plain text, we will use

And if you really want to append to html email content too, you can add this filter too

Adding Unsubscribe link to specific BuddyPress emails

If you want, you can insert the email notification unsubscribe link in specific BuddyPress emails too.  You can use the tokens and edit the emails in dashboard to do that. The relevant token is {{unsubscribe}}.

Here is what you should insert in the html email

And in the plan text email, we don’t need html tag, we can simply use the unsubscribe token as

That’s all.

Hope you are enjoying BuddyPress.  We are certainly loving it.

Leave a Reply

Are you looking for support?

Please ask support questions in BuddyDev Forum and help us serve you better. Please use comment for general discussion/feature suggestions.

Your email address will not be published. All the fields marked as * are required.

If you are posting code, please use <pre> { Your Code Block } </pre>. Example:- <pre> echo $name; </pre>

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">


Subscribe