-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpage-settings.php
237 lines (206 loc) · 8.18 KB
/
page-settings.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<script>
var postmark = postmark || {};
postmark.settings = <?php echo wp_json_encode( $this->settings ); ?>;
</script>
<?php
// Registers script for JS.
wp_register_script( 'pm-js', plugins_url( 'assets/js/admin.js', __FILE__ ), '', null, true );
// Enqueues script for JS.
wp_enqueue_script( 'pm-js' );
// Registers script for CSS.
wp_register_style( 'pm-styles', plugins_url( 'assets/css/admin.css', __FILE__ ) );
// Enqueues script for CSS.
wp_enqueue_style( 'pm-styles' );
wp_nonce_field( 'postmark_nonce' );
?>
<div class="wrap">
<div class="logo-bar">
<a href="https://postmarkapp.com/" target="_blank"><img src="<?php echo esc_url( POSTMARK_URL . '/assets/images/logo.png' ); ?>" width="130" height="21" alt="" /></a>
</div>
<h1 class="nav-tab-wrapper">
<a class="nav-tab" rel="general">General</a>
<a class="nav-tab" rel="test">Send Test Email</a>
<a class="nav-tab" rel="overrides">Overrides</a>
<!-- Only show Logs tab if logging is enabled -->
<?php if ( isset( $this->settings['enable_logs'] ) && true == $this->settings['enable_logs'] ) : ?>
<a class="nav-tab" rel="log" id="pm-log-nav-tab">Logs</a>
<?php else : ?>
<a class="nav-tab hidden" rel="log" id="pm-log-nav-tab">Logs</a>
<?php endif; ?>
<?php if ( isset( $_ENV['POSTMARK_PLUGIN_TESTING'] ) && 'POSTMARK_PLUGIN_TESTING' === $_ENV['POSTMARK_PLUGIN_TESTING'] ) : ?>
<a class="nav-tab" rel="plugin-testing">Plugin Testing</a>
<?php endif; ?>
</h1>
<div class="updated notice pm-notice hidden"></div>
<div class="tab-content tab-general">
<table class="form-table">
<tr>
<th><label>Enabled?</label></th>
<td>
<input type="checkbox" class="pm-enabled" value="1" />
<span class="footnote">Send emails using Postmark</span>
</td>
</tr>
<tr>
<th><label>API Key</label></th>
<td>
<input type="text" class="pm-api-key" value="" />
<div class="footnote">Your API key is in the <strong>API Tokens</strong> tab of your <a href="https://account.postmarkapp.com/servers" target="_blank">Postmark Server</a>.</div>
</td>
</tr>
<tr>
<th><label>Message Stream</label></th>
<td>
<input type="text" class="pm-stream-name" value="" placeholder="outbound" />
<div class="footnote">Optional - Default is 'outbound' if blank.</div>
</td>
</tr>
<tr>
<th><label>Sender Email</label></th>
<td>
<input type="text" class="pm-sender-address" value="" />
<div class="footnote">This email must be a verified <a href="https://account.postmarkapp.com/signatures" target="_blank">Sender Signature</a>. It will appear as the "from" address on all outbound emails.</div>
</td>
</tr>
<tr>
<th><label>Force HTML</label></th>
<td>
<input type="checkbox" class="pm-force-html" value="1" />
<span class="footnote">Force emails to be sent as HTML.</span>
</td>
</tr>
<tr>
<th><label>Track Opens</label></th>
<td>
<input type="checkbox" class="pm-track-opens" value="1" />
<span class="footnote">Track email opens (<code>Force HTML</code> is required).</span>
</td>
</tr>
<tr>
<th><label>Track Links</label></th>
<td>
<input type="checkbox" class="pm-track-links" value="1" />
<span class="footnote">Track links in emails.</span>
</td>
</tr>
<tr>
<th><label>Enable Logs</label></th>
<td>
<input type="checkbox" class="pm-enable-logs" value="1" />
<span class="footnote">Log send attempts for historical/troubleshooting purposes (Recommended).</span>
</td>
</tr>
</table>
<div class="submit">
<input type="submit" class="button-primary save-settings" value="Save Changes" />
</div>
</div>
<div class="tab-content tab-test">
<table class="form-table">
<tr>
<th><label>To</label></th>
<td><input type="text" class="pm-test-email" value="" placeholder="[email protected]" /></td>
</tr>
<tr>
<th><label>From (optional)</label></th>
<td><input type="text" class="pm-test-email-sender" value="" placeholder="[email protected]" /></td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="with_tracking_and_html" class="pm-test-with-opens" value="" />Send test as HTML, with Open and Link Tracking enabled.</td>
</tr>
</table>
<div class="submit">
<input type="submit" class="button-primary send-test" value="Send Test Email" />
</div>
</div>
<div class="tab-content tab-overrides">
<h2>Developer overrides</h2>
<p>Instead of using <code>Force HTML</code>, we recommend setting <code>wp_mail</code> headers when possible.</p>
<pre>
$headers = array();
// Override the default 'From' address
$headers['From'] = '[email protected]';
// Send the message as HTML
$headers['Content-Type'] = 'text/html';
// Enable open tracking (requires HTML email enabled)
$headers['X-PM-Track-Opens'] = true;
// Enable or disable link tracking
// Options are None, HtmlAndText, TextOnly, or HtmlOnly
$headers['X-PM-Track-Links'] = 'HtmlAndText';
// Send the email
$response = wp_mail( $to, $subject, $message, $headers );
</pre>
To learn more about <code>wp_mail</code>, see the <a href="https://developer.wordpress.org/reference/functions/wp_mail/">WordPress Codex page.</a>
</div>
<!-- Sending logs tab -->
<!-- Only show Log tab if logging is enabled -->
<?php if ( isset( $this->settings['enable_logs'] ) && true == $this->settings['enable_logs'] ) : ?>
<div class="tab-content tab-log">
<?php
global $wpdb;
$table = $wpdb->prefix . 'postmark_log';
// Checks how many logs are in the logs table.
$count = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $table );
// Only shows some logs if some logs are stored.
if ( $count > 0 ) {
// Pulls sending logs from db to display in UI. prepare() used to prevent SQL injections
$result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $table ORDER BY log_entry_date DESC LIMIT %d", 10 ) );
// Logs table header HTML.
echo '<table class="pm-log" id="pm-log-table">
<thead>
<th>Date</th>
<th>From</th>
<th>To</th>
<th>Subject</th>
<th>Postmark API Response</th>
</thead><tbody>';
// Builds HTML for each log to show as a row in the logs table.
foreach ( $result as $row ) {
echo '<tr><td align="center">' . date( 'Y-m-d h:i A', strtotime( esc_html( $row->log_entry_date ) ) ) . '</td><td align="center"> ' . esc_html( $row->fromaddress ) . '</td><td align="center"> ' . esc_html( $row->toaddress ) . '</td><td align="center"> ' . esc_html( $row->subject ) . '</td><td align="center"> ' . $row->response . '</td></tr>';
}
echo '</tbody></table>';
// Shows a 'Load More' button if more than 10 logs in logs table.
if ( $count > 10 ) {
echo '<div class="submit load-more">
<input type="submit" class="button-primary" value="Load More" /></div>';
}
} else {
echo '<h2 align="center">No Logs</h2>';
}
?>
<?php endif; ?>
</div>
<?php if ( isset( $_ENV['POSTMARK_PLUGIN_TESTING'] ) && 'POSTMARK_PLUGIN_TESTING' === $_ENV['POSTMARK_PLUGIN_TESTING'] ) : ?>
<div class="tab-content tab-plugin-testing">
<table class="form-table" style="max-width:740px;">
<tr>
<th><label>Headers</label></th>
<td>
<textarea name="pm-plugin-test-headers" class="pm-plugin-test-headers" cols=80 placeholder="Reply-To: [email protected]"></textarea>
</td>
</tr>
<tr>
<th><label>Subject</label></th>
<td>
<input type="text" name="pm-plugin-test-subject" class="pm-plugin-test-subject" placeholder="Dear Emily, I just wanted to say hello..."/>
</td>
</tr>
<tr>
<th><label>Body</label></th>
<td>
<textarea name="pm-plugin-test-body" class="pm-plugin-test-body" placeholder="Hi there!" cols=80 ></textarea>
</td>
</tr>
<tr>
<th><label>To Address</label></th>
<td>
<input type="text" name="pm-plugin-test-to-address" class="pm-plugin-test-to-address" value="" placeholder="[email protected]" />
</td>
</tr>
</table>
<div class="submit">
<input type="submit" class="button-primary plugin-send-test" value="Send Test Message" />
</div>
</div>
<?php endif; ?>
</div>