How to Replace Default Email Template in Plugin

WordPress Event Management, Calendars & Registration Forums Frontend Submissions How to Replace Default Email Template in Plugin

This topic contains 2 replies, has 2 voices, and was last updated by  Brian Hanna 7 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22967

    I have looked through the source code quite a bit (particularly in the includes/email-lib.php file), but am struggling to find out how I might override the path for the default email template in a plugin. It seems pretty straightforward for a theme, but we want to bundle a default email template with one of our plugins. For much of your plugins there are actions and filters for everything which we have loved, but not seeing how it might be possible here. Any ideas?

    Brian Hanna
    #22978

    Hi Brian,

    It isn’t currently possible for the e-mail template to be over-ridden by a plugin. The plug-in current looks in three locations: the child theme (if it exists), the parent theme and the template directory in Event Organiser FES.

    The only way to get round this is, is that there is a filter eventorganiser_template_{template-name} (replace {template-name} with the name of the template). This filters the entire e-mail body, so you could replace that with your own mark-up / e-mail template:

    add_filter( 'eventorganiser_template_{...}', function( $body ) {
         //Replace $body with the markup for the e-mail. e.g:
         ob_start();
         include( '/absolute/path/to/template.php' );
         $body = ob_get_contents(); // assign buffer contents to variable
         ob_end_clean(); // end buffer and remove buffer contents
         return $body;
    } );
    
    Stephen Harris
    #22979

    Perfect, you are a rockstar – did exactly what I needed it to do. Thanks!

    Brian Hanna
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.