Skip to content

Commit fd6406d

Browse files
Rich Lelandrajumsys
authored andcommitted
Add template field, send using substitution data
Refs #10
1 parent 33cfc66 commit fd6406d

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

trunk/admin.widget.class.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public function admin_page_init()
131131
add_settings_field('sending_method', 'Method*', array($this, 'render_sending_method_field'), 'sp-options', 'general');
132132
add_settings_field('password', 'API Key*', array($this, 'render_password_field'), 'sp-options', 'general');
133133
add_settings_field('enable_tracking', 'Enable tracking*', array($this, 'render_enable_tracking_field'), 'sp-options', 'general');
134+
add_settings_field('template', 'Template*', array($this, 'render_template_field'), 'sp-options', 'general');
134135

135136
add_settings_section('overrides', 'Overrides', null, 'sp-overrides');
136137
add_settings_field('from_name', 'From name', array($this, 'render_from_name_field'), 'sp-overrides', 'overrides');
@@ -154,6 +155,10 @@ public function sanitize($input)
154155
$new_input['from_name'] = trim($input['from_name']);
155156
}
156157

158+
if (!empty($input['template'])) {
159+
$new_input['template'] = trim($input['template']);
160+
}
161+
157162
if (empty($input['password'])) {
158163
add_settings_error('Password', esc_attr('password'), 'API Key is required', 'error');
159164
} else {
@@ -222,6 +227,14 @@ public function render_password_field()
222227
);
223228
}
224229

230+
public function render_template_field()
231+
{
232+
printf(
233+
'<input type="text" id="template" name="sp_settings[template]" class="regular-text" value="%s" /><br/>',
234+
isset($this->options['template']) ? $this->options['template'] : ''
235+
);
236+
}
237+
225238
public function render_from_email_field()
226239
{
227240
$hint = 'Important: Domain must match with one of your verified sending domains.';

trunk/mailer.http.class.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ protected function get_request_body()
6262
)
6363
);
6464

65-
switch ($this->ContentType) {
66-
case 'multipart/alternative':
67-
$body['content']['html'] = $this->Body;
68-
$body['content']['text'] = $this->AltBody;
69-
break;
70-
case 'text/plain':
71-
$body['content']['text'] = $this->Body;
72-
break;
73-
default:
74-
$body['content']['html'] = $this->Body;
75-
break;
65+
if (!empty($this->options['template'])) {
66+
$body['content']['template_id'] = $this->options['template'];
67+
$body['substitution_data']['content'] = $this->Body;
68+
} else {
69+
switch($this->ContentType) {
70+
case 'multipart/alternative':
71+
$body['content']['html'] = $this->Body;
72+
$body['content']['text'] = $this->AltBody;
73+
break;
74+
case 'text/plain':
75+
$body['content']['text'] = $this->Body;
76+
break;
77+
default:
78+
$body['content']['html'] = $this->Body;
79+
break;
80+
}
7681
}
7782

7883
$replyTo = $this->get_reply_to();
@@ -242,4 +247,4 @@ protected function get_headers()
242247

243248
return $formatted_headers;
244249
}
245-
}
250+
}

trunk/sparkpost.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class SparkPost
1616
'from_name' => '',
1717
'from_email' => '',
1818
'enable_sparkpost' => false,
19-
'enable_tracking' => true
19+
'enable_tracking' => true,
20+
'template' => ''
2021
);
2122

2223
var $options;

0 commit comments

Comments
 (0)