One of the new great features included with the WP Job Manager Emails 2.0 plugin is the Email Templates feature!
The new email templates feature allows users to select from any of the included (or added by themes, plugins, or your own custom code) templates, to help kickstart creating emails with ease. The core plugin includes 33+ email templates (as of 2.0.0) which include custom ones I created, as well as, default emails sent by the core plugins, converted into templates.
If you’re a theme or plugin developer (or individual developer), you may want to include your own templates, which is very easy to do, and below I will show you exactly how to do this.
Adding Custom Templates
This tutorial is a little rough right now (very rough we will say), and will be updated soon with more details, a clear example, and references to available hooks, and shortcodes. For now here’s the PHPDoc block for the filter:
functions.php
/**
* Filter to add Custom Theme, or Plugin templates
*
* If you want to add custom templates, this is the hook you should use.
* Custom templates should follow the pattern below. Templates should be placed inside the 'templates' array key
* which is an array of non-key arrays.
*
* For the email template post content, you should NOT use HTML as this will be stripped if the user sets the email type
* to plain text. Instead, you should use new line breaks (n), which will be converted to HTML <br> automatically.
*
* Supported shortcodes (NOT WordPress shortcodes, this plugins shortcodes) can be used in almost every field (to, subject, post_content),
* except post_title. If you want to add custom shortcodes, @see WP_Job_Manager_Emails_Shortcodes
*
* The `action` value in the template array of arrays should be the action to associate the template with.
* This is the key of the action/hook, defined in this class, or extending classes @see init_ps_actions() @see init_actions()
*
* @see https://plugins.smyl.es/docs-kb/adding-custom-plugin-or-theme-email-templates/
*
* @since 2.0.0
*
* @param array $templates Array of templates based on active/available hooks
* @param array $ps_actions Array of Post Status actions/hooks
* @param array $core_actions Array of Core actions/hooks
* @param class $this Access to $this current object
*/
add_filter( 'job_manager_emails_hook_templates', 'smyles_test_email_templates', 10, 4 );
function smyles_test_email_templates( $templates, $ps_actions, $core_actions, $that ){
$singular = 'Listify Listing';
$content = '';
$content .= __( 'Hello' ) . "n" . "n";
$content .= sprintf( __( 'A new %1$s has just been submitted by *%2$s*. The details are as follows:' ), $singular, '[company_name]' ) . "n" . "n";
$content .= __( 'This is a custom email template just for the Listify theme! Plugin and theme developers can easily add their own templates! ') . "n" . "n";
$content .= "[divider]" . "n" . "[job_fields]" . "n" . "[/divider]" . "n" . "n";
$content .= "[job_description]" . "n" . sprintf( __( 'The %s description is as follows:' ), $singular ) . "n" . "[/job_description]" . "n" . "n";
$content .= sprintf( __( 'You can view this %1$s here: %2$s' ), $singular, '[view_job_url]' ) . "n";
$content .= sprintf( __( 'You can view/edit this %1$s in the backend by clicking here: %2$s' ), $singular, '[view_job_url_admin]' ) . "n" . "n";
$templates['listify'] = array(
'label' => __( 'Listify Theme Templates' ), // Header text when viewing tab
'tab' => __( 'Listify' ), // Text used for tab .. KEEP THIS SHORT!!
'desc' => __( 'Themes and plugins can add their own custom templates!' ), // Description shown under header text
'templates' => array(
array(
'label' => __( 'New Listify Listing Submitted' ),
'desc' => __( 'This is a custom template specifically for the Listify theme integrated easily with only a few lines of code!' ),
'action' => 'job_manager_job_submitted',
'attachments' => array('company_logo'),
'defaults' => array(
'to' => '[admin_email]',
'post_content' => $content,
'subject' => __( 'New Listify Submission, [job_title]' ),
'post_title' => __( 'New Listify Listing Submitted' ),
)
)
)
);
return $templates;
}
Below you can find links to the private GitHub repo for referenced methods and more information. If you do not have access to the private repo and are a theme or plugin developer, please contact me, otherwise you can look at the URL to determine the file to look at, and the line numbers.
The filter above:
https://github.com/tripflex/wp-job-manager-emails/blob/master/includes/class-hooks.php#L587-L635
init_ps_actions :
Job init_actions :
https://github.com/tripflex/wp-job-manager-emails/blob/master/includes/hooks/class-job.php#L46
Resume init_actions :
https://github.com/tripflex/wp-job-manager-emails/blob/master/includes/hooks/class-resume.php#L92