Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active August 23, 2017 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tripflex/f59aa8dc678153ff3e3529075d297df4 to your computer and use it in GitHub Desktop.
Save tripflex/f59aa8dc678153ff3e3529075d297df4 to your computer and use it in GitHub Desktop.
Example WP Job Manager Emails code to add custom email templates (for developers)
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment