• Hi
    I’m looking for the ability to be able to add an unsubscribe link in the footer of the email template.

    any idea how to go about it?

    its a basic usage features for mailers, hope you’re considering it, if its not already hiding inside.

    thanks!
    Nimrod

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter daberelay

    (@daberelay)

    To whoever needs it like me, and still waits for the developers to provide a solution, here’s what you can do.

    1. Clone the plugin, and rename its package ID so it won’t get overrun in future updates.
    2. edit the replace_placeholders function in /email-templates/includes/class-mailtpl-mailer.php to receive another argument called $args, and merge these args into the list of keys=>values that the plugin supports:

    
    private function replace_placeholders( $email,$args = array() ) {
    	
    	$args = array_merge(array(
    		'%%BLOG_URL%%'         => get_option( 'siteurl' ),
    		'%%HOME_URL%%'         => get_option( 'home' ),
    		'%%BLOG_NAME%%'        => get_option( 'blogname' ),
    		'%%BLOG_DESCRIPTION%%' => get_option( 'blogdescription' ),
    		'%%ADMIN_EMAIL%%'      => get_option( 'admin_email' ),
    		'%%DATE%%'             => date_i18n( get_option( 'date_format' ) ),
    		'%%TIME%%'             => date_i18n( get_option( 'time_format' ) )
    	),$args);
    		
    	$to_replace = apply_filters( 'emailtpl/placeholders', $args);
    

    3. on that same file, find send_email & send_email_postman functions and add this:

    
      $placeholders = array("%%USER_EMAIL%%" => $args["to"]);
    

    and pass it to the replace_placeholders function.

    now you should be able to put “%%USER_EMAIL%% anywhere in the template and get the current addressee’s email address, so the unsubscribe link will relate to the current user.

    You don’t need to clone the plugin , you got filters to do what you just did. Simple enter in your functions.php the following

    add_filter( 'emailtpl/placeholders', 'my_custom_placeholder');
    function my_custom_placeholder($placeholders){
        $placeholders['%%USER_EMAIL%%'] = isset($args["to"]) ? $args["to"] : '';
        return $placeholders;
    } 

    That will keep you safe from future updates unless some major code changes and the filter get renamed

    Thread Starter daberelay

    (@daberelay)

    thanks Damian!

    I wasn’t aware that I could use the $args in the filter, good to know.

    will test now.

    thanks again 🙂
    Nimrod.

    Thread Starter daberelay

    (@daberelay)

    Hi Damian,
    As I suspected, this is not a viable solution, since the $args are not passed to the filter, and therefore I don’t have the addressee information within the filter.

    Would you consider a fix? I’m sure many will enjoy being able to provide a user/email-address-aware email templates…

    Adding args for next version. Remember to check if it’s array before doing anything as it could be phpmailer instance also.

    Thread Starter daberelay

    (@daberelay)

    Hi Damian,

    Thanks for fixing this up in v1.2, but we’re still around the same issue.

    The “to” parameter is not passed on through your code to the placeholders list.

    the only way I can circumvent that, is by manipulating the code to add it (step 3 of my original post here).

    Can you suggest a non-intrusive way of getting the “to” parameter in the placeholder’s list while enjoying safe future upgrades?

    thanks in advance,
    Nimrod

    Thread Starter daberelay

    (@daberelay)

    also, It strikes me odd, and indeed doesn’t sit well with the filter function that you pass different types of objects as the $args second parameter:

    on send_email: you pass $phpmailer to the replace placeholder as second parameter, and $message as the first one.
    $phpmailer->Body = $this->replace_placeholders( $message, $phpmailer );
    to the altBody, you only pass the original body (the email_content filter has no impact).
    $phpmailer->AltBody = $this->replace_placeholders( strip_tags($phpmailer->Body) );

    on send_email_generic and send_email_postman:
    $this->replace_placeholders( $temp_message, $message (or $args) );
    you pass $message/$args as second parameter which is an array, not an object.

    I believe that passing $phpmailer is mistake, the filter shouldn’t be aware of that object…

    Thread Starter daberelay

    (@daberelay)

    Damian, do you maybe have an Idea how to fix this issue?

    To clarify, this is the main problem:
    The “to” parameter is not passed on through your code to the placeholders list.

    the only way I can circumvent that, is by manipulating the code to add it (step 3 of my original post here).

    Can you suggest a non-intrusive way of getting the “to” parameter in the placeholder’s list while enjoying safe future upgrades?

    thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘unsubscribe link’ is closed to new replies.