Bugfix for HTML Email Templates plugin

Hi,

Found a small issue in this plugin. On the admin screen, if you click to expand the list of variables that can be used in the templates, there’s no entry for {USER_NAME} although this can be used in the templates. The highlighted row in the attached image shows where I’ve added it to my installation. The edit is in htmlemail.php > list_placeholders() > $placeholder_desc:

'{USER_NAME}' => __( 'Recipient's Username', 'htmlemail' ),

Additionally, there are no entries in the list for {BG_IMAGE}, {HEADER_IMAGE}, and {EMAIL_TITLE} although they can be used in the templates. Those can be added in the same fashion/location as the above.

Thanks!

  • Panos
    • SLS

    Hi John A. ,

    I have attached 3 files which you can replace:

    1st: wp-content/plugins/htmlemail/htmlemail.php

    2nd: wp-content/plugins/htmlemail/assets/js/htmlemail.js

    3rd: wp-content/plugins/htmlemail/assets/css/htmlemail.css

    You should be able to see the

    {USER_NAME} placeholder which displays the recipients display name

    {EMAIL_TITLE} which by defaults should display the blog title but you can override it be using a snippet like following:

    add_filter( 'wpmudev_htmlemail/email_title', function( $blog_url, $subject, $mail_args ){
    return $subject;
    }, 10, 3 );

    which sets the subject as EMAIL_TITLE.

    {BG_IMAGE} Image used for background. Can be set from the new accordion “Images that can be used in template”.

    {HEADER_IMAGE} Image that can be used as header in the email template. Similar with previous, can be set from “Images that can be used in template”.

    Hope this is helpful to you :slight_smile:

  • John A.
    • The Incredible Code Injector

    Thanks, Panos – I should get time to try this today and will report back. I’m in the middle of converting all the templates to HTML5. I thought it would just take a couple of hours, but it’s looking like it will take 16 hours by the time I’m done making final tweaks and taking screenshots. = I’m uploading them to my GitHub and will start another thread when they’re available. Hopefully, they’ll be worth a ton of Hero Points! :smiley:

  • John A.
    • The Incredible Code Injector

    I’ve had a chance to merge your changes on this end. Thanks for fixing this up! However, there’s still an issue. As you wrote the code, the images are uploaded to the /wp-content/uploads/ directory. This is fine for most situations, but fails if the site is using a CDN.

    For example, let’s say my main site is at https://site.com. Let’s further assume that the uploads directory has been moved with the following directive in wp-config.php:

    define('WP_CONTENT_URL', 'https://cdn.site.com/wp-content');

    The plugin is not adhering to that directive when uploading the images.

    So, the images are uploaded to the main site:

    https://site.com/wp-content/uploads/.../.../image.jpg

    …instead of uploaded to the CDN site at:

    https://cdn.site.com/wp-content/uploads/.../.../image.jpg

    The URLs in the boxes where I uploaded the image(s) do have the correct (CDN) URL – it’s just that the images were not actually uploaded to the CDN, they were uploaded to the main site, so the URLs are broken.

  • John A.
    • The Incredible Code Injector

    It turns out that my CDN defines were not configured correctly and that was causing the images to be uploaded to incorrect locations – I have it fixed and the images are uploading as expected. I can confirm that the issues you noted above were all fixed in your patched files. Thanks so much for working this out!

  • John A.
    • The Incredible Code Injector

    I actually did find some issues, sorry.

    When you click to load a template – if that template has the placeholder {BG_IMAGE} in the markup, the BG_IMAGE part is stripped out and you’re just left with the braces {}.

    Also, the isset() checks on lines 907-908 are not strong enough. If you upload both images, then remove the url from one of the fields, that field is still saved in the serialized data as an empty string – this will pass the isset() test and output <img src=”” /> into the markup.

    Also, you have introduced several images that should have alt tags. Lines 907, 908, and 917.

  • Panos
    • SLS

    Hi John A. ,

    and thanks for your feedback!

    For the first issue, this happens cause it checks if the template has defined “HTMLEMAIL_BUILDER_DEFAULT_BG_IMAGE”. I believe this check can be removed completely as now it has the uploader to manage image easier.

    I have also added another condition where it checks if the image url is empty, not only set.

    I have attached file

    wp-content/plugins/htmlemail/htmlemail.php

    with changes here, please let us know how it works for you :slight_smile:

    Thanks!

  • John A.
    • The Incredible Code Injector

    Hi, Panos, thanks for updating – I can confirm that you have fixed 2 of those 3 issues.

    To finalize this, I added the alt attributes to lines 900, 901, and 910 as noted below. Please consider adding these attributes to the images (even if the attribute is empty) since they are required for HTML5 validation.

    You may also be interested to know that the previous htmlemail.php file you sent was version 2.0.7, but your new file is version 2.0.6. The file does work, it was just inconsistent in the versioning, so I thought I’d mention it.

    Thanks again for working with me to knock this out!! I greatly appreciate your time, effort, and feedback!

    if( is_array( $html_images ) ){

    $bg_image = isset( $html_images['bg'] ) && $html_images['bg'] != '' ? '<img src="' . esc_url( $html_images['bg'] ) . '" alt="" />' : false;
    $header_image = isset( $html_images['header'] ) && $html_images['header'] != '' ? '<img src="' . esc_url( $html_images['header'] ) . '" alt="" />' : false;

    }

    if( ! $bg_image ){
    $bg_image = defined( 'BUILDER_DEFAULT_BG_IMAGE' ) ? $this->theme_url . '/' . constant( 'BUILDER_DEFAULT_BG_IMAGE' ) : '';
    }

    if( ! $header_image ){
    $header_image = defined( 'BUILDER_DEFAULT_HEADER_IMAGE' ) ? '<img src="' . $this->theme_url . '/' . constant( 'BUILDER_DEFAULT_HEADER_IMAGE' ) . '" alt="" />' : '';
    }

  • John A.
    • The Incredible Code Injector

    After a bit more working with this, I did spot another issue.

    Down around line 905, there is a check if BUILDER_DEFAULT_BG_IMAGE is defined. The problem is that it will never be defined here because the index.php file from the current theme hasn’t been included. So, right before that check, we need something like:

    include_once( $this->template_directory . INSERT_CURRENT_THEME_NAME_HERE . '/index.php' );

    …and that should do it! :slight_smile:

  • Tyler Postle
    • CGO

    Hey John,

    I just tested out Panos' beta above and the theme applied fine for me when I tested:

    Did you make sure you saved it before sending the test? I've made same mistake before, just loading the template so all the code is there but then didn't save it before I sent the test email.

    If you do try it again and experience any issues then just let us know. It will go through further testing by our QA team before it's released :slight_smile:

    Cheers,

    Tyler

  • John A.
    • The Incredible Code Injector

    Hi, Tyler,

    I only updated the htmlemail.php file and not all the beta files, so the error was mine. I uploaded the full beta and it worked. However, the fix introduced several new bugs that I was able to find within a few minutes. A good proper pass through QA would be great.

    1) In the slider where you select themes, the first theme's display is broken; see screenshot 1.

    2) In the Preview window, the images (header and background) do not display; screenshot 2.

    3) In the sent email, the header image displays, the background image doesn't; screenshot 3.

    Thanks.

  • John A.
    • The Incredible Code Injector

    Hi Kasia,

    I’ve got 8 fairly meaty plugins to write for a new client by 04/10, so it’s unlikely that I’ll be able to test the beta within a reasonable timeframe. I’ll still be subscribed to the thread, though, so do let me know. Thanks for the update.

    John

  • Panos
    • SLS

    Hi guys!

    Sorry for missing this.

    I have attached a version that should be resolving the slider layout.

    Regarding the background images not showing it’s because it uses the obsolete element attribute background in the table’s td. Instead you can use the style attribute with the background property.

    I have changed this in the attached version, but you’ll need to re-select a template to see this and that means that you can loose any customizations you have. So if you have any customisations in the html editor it’s better to change that manually.

    Cheers!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.