Last active
December 19, 2016 17:36
-
-
Save elimn/befb40c75b87b06b604a0838fd283279 to your computer and use it in GitHub Desktop.
MT | Send an email Tribe style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Sends an email Tribe style | |
* | |
* This will retrieve a template file and use it to populate the content body. | |
* Defaults to HTML emails. | |
* | |
* @param string $email_name Name of this email in snake_case format, used as suffix in apply_filter(). | |
* @param string|array $to Array or comma-separated list of email addresses to send message. | |
* @param string $subject Email subject. | |
* @param array $template Arguments passed to tribe_get_template_part() for populating the message body. | |
* @param array $args See tribe_mail filter for full list. | |
* | |
* @see tribe_get_template_part() for valid $template arguments. | |
* @see tribe_mail Filter for full list of args. | |
* | |
* @return bool Indicates if email was sent successfully. | |
*/ | |
function tribe_mail( $email_name, $to, $subject, $template, $args = array() ) { | |
$args = wp_parse_args( $args, array( | |
'headers' => array( 'Content-type: text/html' ), | |
'attachments' => array(), | |
'send_email' => true, | |
) ); | |
$args['to'] = $to; | |
$args['subject'] = $subject; | |
$args['template'] = $template; | |
/** | |
* Alter tribe email parameters before they are sent | |
* | |
* @param array $args { | |
* All of the attributes for this email. | |
* | |
* @param string|array $to Array or comma-separated list of email addresses to send message. | |
* @param string $subject Email subject. | |
* @param array $template Arguments passed to tribe_get_template_part() for populating the message body. | |
* @param string|array $headers Additional headers. | |
* @param string|array $attachments Files to attach. | |
* @param bool $send_email Whether or not to send the email. | |
* } | |
* @param string $email_name Unique name for this email. | |
*/ | |
$args = apply_filters( 'tribe_mail', $args, $email_name ); | |
/** | |
* Dynamic filter that can be used to filter a given email | |
* | |
* Concatenates tribe_mail_ with the dynamic email name. | |
* | |
* @see tribe_mail for detailed documentation on $args. | |
*/ | |
$args = apply_filters( 'tribe_mail_' . $email_name, $args ); | |
$message = call_user_func_array( 'tribe_get_template_part', $args['template'] ); | |
$success = false; | |
if ( $args['send_email'] ) { | |
$success = wp_mail( $args['to'], $args['subject'], $message, $args['headers'], $args['attachments'] ); | |
} | |
return $success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment