1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121:
<?php
class Inbound_Mailer_Forms_Integration {
public function __construct() {
self::add_hooks();
}
public static function add_hooks() {
add_filter( 'inbound-forms/email-reponse-hijack' , array( __CLASS__ , 'send_confirmation_email') , 10 , 3 );
add_action( 'inbound-forms/before-email-reponse-setup' , array( __CLASS__ , 'extend_inbound_forms' ));
}
public static function extend_inbound_forms( $email_template ) {
global $post;
$email_template = get_post_meta( $post->ID, 'inbound_email_send_notification_template' , TRUE );
$emails = Inbound_Mailer_Post_Type::get_automation_emails_as( 'ARRAY' );
if (!$emails) {
$emails[] = __( 'No Automation emails detected. Please create an automated email first.' , 'inbound-pro' );
}
?>
<div style='display:block; overflow: auto;'>
<div id=''>
<label for="inbound_email_send_notification_template"><?php _e( 'Select Response Email Template' , 'inbound-pro' ); ?></label>
<select name="inbound_email_send_notification_template" id="inbound_email_send_notification_template">
<option value='custom' <?php selected( 'custom' , $email_template); ?>><?php _e( 'Do not use a premade email template' , 'inbound-pro' ); ?></option>
<?php
foreach ($emails as $id => $label) {
echo '<option value="'.$id.'" '. selected($id , $email_template , false ) .'>'.$label.'</option>';
}
?>
</select>
</div>
</div>
<?php
}
public static function send_confirmation_email( $confirm_subject , $form_meta_data , $form_post_data) {
$template_id = $form_meta_data['inbound_email_send_notification_template'][0];
if ( !$template_id || $template_id == 'custom' ) {
return false;
}
$form_post_data = array_map('urldecode' , $form_post_data);
$lead_id = Inbound_API::leads_get_id_from_email( $form_post_data['wpleads_email_address'] );
$vid = Inbound_Mailer_Variations::get_next_variant_marker( $template_id );
$args = array(
'email_id' => $template_id,
'vid' => $vid,
'email_address' => $form_post_data['wpleads_email_address'],
'lead_id' => $lead_id,
'tags' => array('inbound-forms'),
'email_recipients' => explode(',' , $form_post_data['inbound_form_lists'])
);
$response = Inbound_Mail_Daemon::send_solo_email( $args );
return true;
}
public static function filter_lead_email_response_body( $confirm_body , $form_meta_data ) {
$template_id = $form_meta_data['inbound_email_send_notification_template'];
if ( empty($template_id) || $template_id == 'custom' ) {
return $confirm_body;
}
$template_array = self::get_email_template( $template_id );
return ( !empty($template_array['body']) ) ? $template_array['body'] : $confirm_body;
}
}
new Inbound_Mailer_Forms_Integration;