|
1 | 1 | <script>
|
2 |
| -var postmark = postmark || {}; |
3 |
| -postmark.settings = <?php echo json_encode( $this->settings ); ?>; |
| 2 | + var postmark = postmark || {}; |
| 3 | + postmark.settings = <?php echo json_encode( $this->settings ); ?>; |
4 | 4 | </script>
|
5 |
| -<script src="<?php echo POSTMARK_URL; ?>/assets/js/admin.js"></script> |
6 |
| -<link href="<?php echo POSTMARK_URL; ?>/assets/css/admin.css" rel="stylesheet"> |
7 |
| -<?php wp_nonce_field( 'postmark_nonce' ); ?> |
| 5 | +<?php |
| 6 | + |
| 7 | +// Registers script for JS. |
| 8 | +wp_register_script('pm-js', |
| 9 | + plugins_url( 'assets/js/admin.js', __FILE__ ) |
| 10 | +); |
| 11 | + |
| 12 | +// Enqueues script for JS. |
| 13 | +wp_enqueue_script( 'pm-js' ); |
| 14 | + |
| 15 | +// Registers script for CSS. |
| 16 | +wp_register_style( 'pm-styles', |
| 17 | + plugins_url( 'assets/css/admin.css', __FILE__ ) |
| 18 | +); |
| 19 | + |
| 20 | +// Enqueues script for CSS. |
| 21 | +wp_enqueue_style( 'pm-styles' ); |
| 22 | + |
| 23 | +wp_nonce_field( 'postmark_nonce' ); |
| 24 | + |
| 25 | +?> |
8 | 26 | <div class="wrap">
|
9 | 27 | <div class="logo-bar">
|
10 | 28 | <a href="https://postmarkapp.com/" target="_blank"><img src="<?php echo POSTMARK_URL; ?>/assets/images/logo.png" width="130" height="21" alt="" /></a>
|
|
14 | 32 | <a class="nav-tab" rel="general">General</a>
|
15 | 33 | <a class="nav-tab" rel="test">Send Test Email</a>
|
16 | 34 | <a class="nav-tab" rel="overrides">Overrides</a>
|
| 35 | + <!-- Only show Log tab if logging is enabled --> |
| 36 | + <?php if ( $this->settings['enable_logs']) : ?> |
| 37 | + <a class="nav-tab" rel="log" id="pm-log-nav-tab">Logs</a> |
| 38 | + <?php else : ?> |
| 39 | + <a class="nav-tab hidden" rel="log" id="pm-log-nav-tab">Logs</a> |
| 40 | + <?php endif; ?> |
17 | 41 |
|
18 | 42 | <?php if ( isset($_ENV['POSTMARK_PLUGIN_TESTING']) && 'POSTMARK_PLUGIN_TESTING' == $_ENV['POSTMARK_PLUGIN_TESTING'] ) : ?>
|
19 |
| - <a class="nav-tab" rel="plugin-testing">Plugin Testing</a> |
20 |
| - <?php endif; ?> |
| 43 | + <a class="nav-tab" rel="plugin-testing">Plugin Testing</a> |
| 44 | + <?php endif; ?> |
21 | 45 | </h1>
|
22 | 46 |
|
23 | 47 | <div class="updated notice pm-notice hidden"></div>
|
24 | 48 |
|
25 | 49 | <div class="tab-content tab-general">
|
26 |
| - <table class="form-table" style="max-width:740px;"> |
| 50 | + <table class="form-table"> |
27 | 51 | <tr>
|
28 | 52 | <th><label>Enabled?</label></th>
|
29 | 53 | <td>
|
|
59 | 83 | <span class="footnote">Track email opens (<code>Force HTML</code> is required).</span>
|
60 | 84 | </td>
|
61 | 85 | </tr>
|
| 86 | + <tr> |
| 87 | + <th><label>Enable Logs</label></th> |
| 88 | + <td> |
| 89 | + <input type="checkbox" class="pm-enable-logs" value="1" /> |
| 90 | + <span class="footnote">Log send attempts for historical/troubleshooting purposes (Recommended).</span> |
| 91 | + </td> |
| 92 | + </tr> |
62 | 93 | </table>
|
63 | 94 |
|
64 | 95 | <div class="submit">
|
|
106 | 137 | </pre>
|
107 | 138 | To learn more about <code>wp_mail</code>, see the <a href="https://developer.wordpress.org/reference/functions/wp_mail/">WordPress Codex page.</a>
|
108 | 139 | </div>
|
| 140 | + |
| 141 | + <!-- Sending logs tab --> |
| 142 | + <div class="tab-content tab-log"> |
| 143 | + |
| 144 | + <?php |
| 145 | + global $wpdb; |
| 146 | + |
| 147 | + $table = $wpdb->prefix . "postmark_log"; |
| 148 | + |
| 149 | + // Checks how many logs are in the logs table. |
| 150 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $table ); |
| 151 | + |
| 152 | + // Only shows some logs if some logs are stored. |
| 153 | + if ($count > 0) { |
| 154 | + |
| 155 | + // Pulls sending logs from db to display in UI. prepare() used to prevent SQL injections |
| 156 | + $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $table ORDER BY time DESC LIMIT %d", 10)); |
| 157 | + |
| 158 | + // Logs table header HTML. |
| 159 | + echo "<table class=\"pm-log\" id=\"pm-log-table\"> |
| 160 | + <thead> |
| 161 | + <th>Date</th> |
| 162 | + <th>From</th> |
| 163 | + <th>To</th> |
| 164 | + <th>Subject</th> |
| 165 | + <th>Postmark API Response</th> |
| 166 | + </thead><tbody>"; |
| 167 | + |
| 168 | + // Builds HTML for each log to show as a row in the logs table. |
| 169 | + foreach($result as $row) |
| 170 | + { |
| 171 | + echo "<tr><td align=\"center\">" . get_date_from_gmt($row->time, get_option('date_format') . ' - ' . get_option('time_format') ) . "</td><td align=\"center\"> " . $row->fromaddress . "</td><td align=\"center\"> " . $row->toaddress . "</td><td align=\"center\"> " . $row->subject . "</td><td align=\"center\"> " . $row->response . "</td></tr>"; |
| 172 | + } |
| 173 | + |
| 174 | + echo "</tbody></table>"; |
| 175 | + |
| 176 | + // Shows a 'Load More' button if more than 10 logs in logs table. |
| 177 | + if ($count > 10) { |
| 178 | + echo '<div class="submit load-more"> |
| 179 | + <input type="submit" class="button-primary" value="Load More" /></div>'; |
| 180 | + } |
| 181 | + } else { |
| 182 | + echo '<h2 align="center">No Logs</h2>'; |
| 183 | + } |
| 184 | + ?> |
| 185 | + |
| 186 | + </div> |
| 187 | + |
109 | 188 | <?php if ( isset($_ENV['POSTMARK_PLUGIN_TESTING']) &&'POSTMARK_PLUGIN_TESTING' == $_ENV['POSTMARK_PLUGIN_TESTING'] ) : ?>
|
110 | 189 | <div class="tab-content tab-plugin-testing">
|
111 | 190 | <table class="form-table" style="max-width:740px;">
|
|
0 commit comments