Easy Digital Downloads has a templating system for emailed purchase receipts that allow users / developers to create their own templates that are used for the purchase receipts. In this video overview, I want to walk you through how this system works. Building extensible modules within your plugins is something you should always strive for, and seeing how real world examples work definitely helps immensely.

To see an example of the email templates I’m referring to, take a look at the Email Templates add-on that is available.

The templating system was complex to build and has quite a few different components, but once it was complete, registering / building new templates is a piece of cake. To setup a new template, just two functions are required (with one more optional). There is one function to register the template with Easy Digital Downloads and one function to setup the HTML for the template:

// register the custom email template
function pw_edd_get_email_templates( $templates ) {
 
	$templates['my_custom_template'] = 'My Custom Template Name';
 
	return $templates;
}
add_filter('edd_email_templates', 'pw_edd_get_email_templates');
 
// create the HTML for the custom template
function pw_edd_custom_email_template() {	
 
	echo '<div style="width: 550px; border: 1px solid #1e79c0; background: #ddd; padding: 8px 10px; margin: 0 auto;">';
		echo '<div id="edd-email-content" style="background: #f0f0f0; border: 1px solid #9ac7e1; padding: 10px;">';
			echo '{email}'; // this tag is required in order for the contents of the email to be shown
		echo '</div>';	
	echo '</div>';
 
}
add_action('edd_email_template_my_custom_template', 'pw_edd_custom_email_template');

The video above walks you through how the system that allows these two functions to work was built.

I do not expect you to gain a complete understanding of how the template system works after watching the video, or to have an immediate knowledge of how to build these kind of systems, but I do hope that seeing this gets you thinking about possible applications for your own plugins. This system is an exemplary example of an extensible module within a plugin, and that’s what I really want you to start thinking about more. Take the time to consider how you can make your own plugins more extensible and more friendly for users / developers that with to customize the behavior.

  1. samir

    can you make a wordpress theme tutorials series
    thank you very mutch your tutorials are very usefull

    • Pippin

      No sorry, I only do plugin tutorials on this site.