Replace nl2br with wpautop
-
Hi, Haet!
First, congrats for the plugin, I’ve just found it and loved it! I’ll start to using it for every project.
I’ve been having some issues using forms plugins and email templates for WordPress. I’m currently using Caldera Forms to create forms. I’ve tested many email template plugins but yours works the best. With only one small exception: line breaks. Let me explain:
When I create a form using Caldera Forms, for example, I have the possibility to format the email that will be sent using html (the TinyMCE editor). This way, the message comes formatted. Caldera Forms is using
nl2br
function to include line breaks.Then, your plugin (and many more) gets all the email data (including the formatted message), wraps in the template, and sends it. I checked your code and I saw that the plugin use
nl2br
too. This way, the function duplicates the line breaks, and the resulting email comes with lots of line breaks.I digged both on the Caldera Forms and your plugin, to check what can be done to solve it. What I figured is that no matter if Caldera Forms uses
nl2br
or another WP native function, thewpautop
, the line breaks still is wrong. So, I’d like to suggest a fix for this issue:On the file
class-haet-mail.php
, at line 244, replace:$message = nl2br($message);
with
$message = wpautop($message);
This way, the
wpautop
function adds line breaks, wraps paragraphs and allow a better compatibility with Caldera Forms and probably other plugins.I checked another email template plugin, WP Email Template, and it’s working good. I saw the plugin code and they are using
wpautop
to format the message string. So, I think that this fix could make your plugin works better with form builders.
- The topic ‘Replace nl2br with wpautop’ is closed to new replies.