• Resolved bengallienne

    (@bengallienne)


    Hi,
    We use your plugin to send email campaigns, and have noticed in the most recent version that the post content sent to Benchmark from the plugin no longer has any filters applied to it or any means of hooking in to the process to allow us to add / manipulate the html sent to Benchmark. This means we can’t include content from custom fields and related posts etc. Therefore we would have to include all the HTML every time in the post being sent, rather than do any kind of templating.

    I think this could be easily resolved by providing a filter in the create_email function of the class.api.php file, after you get the post, and before running through the sprintf function.

    So after these to lines of code there;
    // Tweak Template
    $post = get_post( $post_id );

    you could add something like;
    $post_html = apply_filters( ‘benchmark_email_campaign_body_html’, $post );

    And then change the sprintf that follows to use this variable instead of the ‘$post->post_content’ variable, and then developers could hook in at that point, manipulate the html and return it before sending on to Benchmark.

    This would make it easy for us to then send emails from posts using your system but style them as we want. Would that be possible please?

    Thanks for your help in advance.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Sean Conklin

    (@seanconklin)

    Hello @bengallienne. Thanks for reaching out ??

    I’ve updated the dev copy of the code on GitHub here: https://github.com/Coded-Commerce-LLC/WP-Benchmark-Email

    Feel free to give it a try and let me know how it works for you. Keep your plugin folder benchmark-email-lite so it stays connected with the upstream repository for releases.

    We’re working on a few updates and getting a maintenance release out in the coming days.

    I changed that function to apply filters for wpbme_post_content including the $post_id argument if that might help with your filter. It’s important to avoid any conflicts with the drag/drop editor so the post body can be wrapped within that interface for email context ( header, footer, sidebars ).

    I also added apply_filters( 'the_content', ... ) to do shortcodes, autop, etc. That does not process Gutenberg blocks (leaves them raw HTML), which thus far is not translated into Benchmark’s email editor. With Gutenberg maturing that might be for the roadmap.

    When we release this I’ll put a new FAQ that explains these filters.

    I also addressed a bug in the class.admin.php where the email creation endpoint inside ui.benchmarkemail.com seems to have changed and the whole post-to-campaign feature was failing. So this will be a fast-tracked release!

    Please note that with recent browser CORS restrictions the iFrame initially fails to authenticate and you will need to click the link to open Benchmark Interface in a new tab with single-sign-on. At least that’s what’s been happening to me until I first authenticate it in a new tab then restart my browser. After that the iFrame seems to work again ??

    Thread Starter bengallienne

    (@bengallienne)

    Hi Sean,

    Thanks for the super fast response! I’ve had a look at the code and it’s almost exactly what I need. However in this particular situation for this particular client, I need to wrap the title and the content in a div together (to make a box on a coloured background), and also hook in other data from custom fields on the post beneath it. The new $post_html sprintf doesn’t quite allow for that, but I see why you have done it as you have. Can I suggest one final filter pass (after everything) that allows devs to completely adjust things if they need to, like in this case? So just above the line

    $body = [ 'Detail' => [ 'TemplateContent' => $TemplateContent ] ];

    We add one last filter like this;

    $TemplateContent = apply_filters('wpbme_custom_campaign_content', $TemplateContent, $post, $post_title, $post_content);

    What do you think? Equally if you are happy to accept a pull request I can put something straight in the repo you posted above?

    Thanks again!

    Ben

    Plugin Author Sean Conklin

    (@seanconklin)

    Happy to help! I did another update to the GitHub project for you:

    – Added the new filter wpbme_email_html for the whole email body that gets inserted into the static drag-drop editor template from Benchmark Email.
    – Changed the argument from post_id to post for convenience.

    So you can filter post_content, post_title, and email_html in separate functions with each receiving the post object argument.

    If it helps I can add style attributes calling further filters to insert your style code into each main element, even a DIV wrapper. Just let me know if that would make a difference.

    Also, I can pass along the email title, subject, author email if any of those would help.

    Thread Starter bengallienne

    (@bengallienne)

    Hi Sean,

    This is almost there now, thanks. The only remaining issues I have is including I have is including background colours and images. The particular client in this case wants the email body to have a background colour and image, and the code you have provided to put the content inside the drag and drop editor doesn’t allow me to do that. How should we go about setting that up please? The example I provided above does work for this, but as you rightly pointed out means the content we send ends up not in the drag and drop editor. That doesn’t matter for our use case as the client won’t ever edit it in Benchmark, but it makes sense for your plugin for that to happen. I have some example screenshots of what we end up with in each case that I can send if you want?

    Thanks,

    Ben

    Plugin Author Sean Conklin

    (@seanconklin)

    I’ve added a new filter to support the “Custom” email formatting with no template for the drag/drop builder. In my tests it worked loading the side-by-side code-preview paneled custom builder in the Benchmark interface.

    Here’s a summary with examples of all new filters for reference:

    add_filter( 'wpbme_email_type', function( $email_type, $post ) {
    	$email_type = 'Custom';
    	return $email_type;
    }, 10, 2 );
    
    add_filter( 'wpbme_post_title', function( $post_title, $post ) {
    	return $post_title . ' Title Modified';
    }, 10, 2 );
    
    add_filter( 'wpbme_post_content', function( $post_content, $post ) {
    	return $post_content . ' Content Modified';
    }, 10, 2 );
    
    add_filter( 'wpbme_email_html', function( $email_html, $post ) {
    	return $email_html . ' HTML Modified';
    }, 10, 2 );
    Thread Starter bengallienne

    (@bengallienne)

    Hi Sean,

    This is great, and I can confirm it is working well, thanks so much!

    Can you let me know what the next steps would be to get this in to an ‘official’ plugin update please?

    Thanks,

    Ben

    Plugin Author Sean Conklin

    (@seanconklin)

    Perfect! I’ll mark this as resolved for now.

    We’re planning to release v3.3 early next week. It’s currently in testing by my colleague @randywsandberg and we’re still putting in minor tweaks.

    I’ll be putting release notes into the GitHub version here shortly, which is currently labeled v3.2.3 so your environments will auto update from the plugin repository upon release as v3.3.

    Plugin Author Sean Conklin

    (@seanconklin)

    v3.3 has just been released. Enjoy! Please report any other requests as they come.

    Thread Starter bengallienne

    (@bengallienne)

    Hi Sean,

    That’s great, thanks! It works really well and I have updated our staging site. I have another issue to raise now I am afraid, but will do it in a new thread.

    Thanks,

    Ben

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Add ability to filter the html being sent to email campaigns’ is closed to new replies.