We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Communicate Module Hooks?

Development and Programming

bkuberek's avatar
bkuberek
124 posts
16 years ago
bkuberek's avatar bkuberek

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

       
bkuberek's avatar
bkuberek
124 posts
16 years ago
bkuberek's avatar bkuberek

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?

       
bkuberek's avatar
bkuberek
124 posts
16 years ago
bkuberek's avatar bkuberek

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.

       
Jack McDade's avatar
Jack McDade
425 posts
16 years ago
Jack McDade's avatar Jack McDade

Nice work bkuberek, i’m looking into modifying the Communicate module myself (specifically to track opens/click rates), so it’s good to know it’s harder than i was hoping.

sigh

       
bkuberek's avatar
bkuberek
124 posts
16 years ago
bkuberek's avatar bkuberek

Though this worked well, I only figure out later that you can also use plugins for the emails. At the bottom of the communicate there is a plugin dropdown. I figure I could use the same code in a plugin instead of an extension.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.