Support » Plugin: Email Users » Add extra filters to personalise the mail

  • Hi,

    We needed some personalization in our mails sent by email-users. To get this working we added extra filters inside of the current plugin. These extra filters make it possible to add user tags that could be replaced.

    I was wondering if we can add this in the current plugin? That way we do not break any future updates.

    We altered a few small things in email-users.php:

    Line 1798:
    $orginalMailtext = $mailtext;

    Line 1837 we added:

    			$mailtext = $orginalMailtext;
    			if (has_filter('mailusers_manipulate_mailtext'))
    			{
    				$mailtext = apply_filters('mailusers_manipulate_mailtext', $orginalMailtext, $recipient) ;
    			}

    Line 1864:
    $originalRecipients = $recipients;

    Line 1905:

    				//  Filter to manipulate the mailtext based on recipient?
    				$mailtext = $orginalMailtext;
                    if (has_filter('mailusers_manipulate_mailtext'))
                    {
    					$recipientUser = false;
    					foreach ($originalRecipients as $key=> $value) {
    						if($value->user_email == $recipient) {
    							$recipientUser = $value;
    							break(1);
    						}
    					}
    					
                        $mailtext = apply_filters('mailusers_manipulate_mailtext', $orginalMailtext, $recipientUser);
                    }

    This option will only work if you place the setting ‘BBC limit’ to 1. Because if you BCC the mail personalization isn’t possible.

    Once this is added you can add personalization tags in your own plugin:

    function opw_mailusers_manipulate_mailtext($mailtext, $recipient) {
    	$mailtext = str_replace('%USER_ID%', $recipient->ID, $mailtext);
    	$mailtext = str_replace('%USER_MAIL%', $recipient->user_email, $mailtext);
    
    	return $mailtext;
    }
    add_filter('mailusers_manipulate_mailtext', 'opw_mailusers_manipulate_mailtext', 10, 3) ;
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.