I need to implement some custom tags within mailinglist templates that will be parsed while sending the emails.
I looked at the whole communicate class and I know where I need the parsing of the tags to happen but there is no hook.
in both single and multiple email on the line
$email->message($message, $plaintext_alt);
I’d like to run the following:
$message = str_replace('{my_custom_tag}', $my_custom_value, $message);
$plaintext_alt = str_replace('{my_custom_tag}', $my_custom_value, $plaintext_alt);
$email->message($message, $plaintext_alt);
I want to change the message on the last stage because I want each user to have a different value for the tag. So for example, when looping through the emails and sending the messages, I can replace the tags with user specific values.
For now I’m assuming I have to modify the core file and add my custom hook so I can then write an extension that will parse the messages.
Is there another way to accomplish this without hacking system/cp/cp.communicate.php?
Will The next release have such hooks in place?
Thanks
This is the hook I have added
for single emails
$edit_messages = array('message' => $message, 'plaintext_alt' => $plaintext_alt);
if (isset($EXT->extensions['communicate_send_single_email']))
{
$edit_messages = $EXT->call_extension('communicate_send_single_email', $edit_messages, $recipient);
}
$message = $edit_messages['message'];
$plaintext_alt = $edit_messages['plaintext_alt'];
for cc and bcc
$edit_messages = array('message' => $message, 'plaintext_alt' => $plaintext_alt);
if (isset($EXT->extensions['communicate_send_cc_bcc_emails']))
{
$edit_messages = $EXT->call_extension('communicate_send_cc_bcc_emails', $edit_messages, $cc, $bcc);
}
$message = $edit_messages['message'];
$plaintext_alt = $edit_messages['plaintext_alt'];
for multiple/batch emails
$edit_recipient = array('key' => $key, 'val' => $val);
$edit_messages = array('message' => $msg, 'plaintext_alt' => $msg_alt);
if (isset($EXT->extensions['communicate_send_multiple_emails']))
{
$edit_messages = $EXT->call_extension('communicate_send_multiple_emails', $edit_messages, $edit_recipient);
}
$msg = $edit_messages['message'];
$msg_alt = $edit_messages['plaintext_alt'];
will this run within this file?
It works great!
It doesn’t work as I wanted with single, cc and bcc emails. The reason is that the recipients is a comma delimited string. In other words, only one email is sent and is impossible to customize the message for each recipient. You can still use it as a way to embed your tags but you can’t rely on sending a unique value to each recipient.
Too bad I had to change a core file and add my hooks. I gotta add it to a list of customizations and make sure I don’t override them next upgrade.
I really hope EE comes out with all imaginable hooks for next release.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.