Changeset 1364176
- Timestamp:
- 03/04/2016 04:00:03 PM (10 years ago)
- Location:
- postmark-approved-wordpress-plugin/trunk
- Files:
-
- 4 added
- 3 deleted
- 2 edited
-
LICENSE.txt (added)
-
images/PM-Logo.jpg (deleted)
-
images/icon.png (deleted)
-
images/logo.png (added)
-
page-settings.php (added)
-
postmark.php (modified) (1 diff)
-
readme.txt (modified) (4 diffs)
-
screenshot-1.jpg (deleted)
-
wp-mail.php (added)
Legend:
- Unmodified
- Added
- Removed
-
postmark-approved-wordpress-plugin/trunk/postmark.php
r1233123 r1364176 1 1 <?php 2 2 /* 3 Plugin Name: Postmark Approved WordPress Plugin 4 Plugin URI: http://www.andydev.co.uk 5 Description: Overwrites wp_mail to send emails through Postmark. 6 Author: Andrew Yates 7 Version: 1.7 8 Author URI: http://www.andydev.co.uk 9 Created: 2011-07-05 10 Modified: 2012-09-10 11 12 Copyright 2011 - 2012 Andrew Yates & Postmarkapp.com 13 14 This program is free software; you can redistribute it and/or modify 15 it under the terms of the GNU General Public License, version 2, as 16 published by the Free Software Foundation. 17 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 3 Plugin Name: Postmark (Official) 4 Plugin URI: https://postmarkapp.com/ 5 Description: Overwrites wp_mail to send emails through Postmark 6 Version: 1.8 7 Author: Andrew Yates & Matt Gibbs 26 8 */ 27 9 28 // Define 29 define('POSTMARK_ENDPOINT', 'http://api.postmarkapp.com/email'); 30 31 // Admin Functionality 32 add_action('admin_menu', 'pm_admin_menu'); // Add Postmark to Settings 33 34 function pm_admin_menu() { 35 add_options_page('Postmark', 'Postmark', 'manage_options', 'pm_admin', 'pm_admin_options'); 36 } 37 38 function pm_admin_action_links($links, $file) { 39 static $pm_plugin; 40 if (!$pm_plugin) { 41 $pm_plugin = plugin_basename(__FILE__); 42 } 43 if ($file == $pm_plugin) { 44 $settings_link = '<a href="options-general.php?page=pm_admin">Settings</a>'; 45 array_unshift($links, $settings_link); 46 } 47 return $links; 48 } 49 50 add_filter('plugin_action_links', 'pm_admin_action_links', 10, 2); 10 class Postmark_Mail 11 { 12 public $settings; 51 13 52 14 53 function pm_admin_options() { 54 if (isset($_POST['submit']) && $_POST['submit'] == "Save") { 55 $pm_enabled = $_POST['pm_enabled']; 56 if($pm_enabled): 57 $pm_enabled = 1; 58 else: 59 $pm_enabled = 0; 60 endif; 15 function __construct() { 16 define( 'POSTMARK_VERSION', '1.8' ); 17 define( 'POSTMARK_DIR', dirname( __FILE__ ) ); 18 define( 'POSTMARK_URL', plugins_url( basename( POSTMARK_DIR ) ) ); 61 19 62 $api_key = $_POST['pm_api_key']; 63 $sender_email = $_POST['pm_sender_address']; 20 add_filter( 'init', array( $this, 'init' ) ); 64 21 65 $pm_forcehtml = $_POST['pm_forcehtml']; 66 if($pm_forcehtml): 67 $pm_forcehtml = 1; 68 else: 69 $pm_forcehtml = 0; 70 endif; 71 72 $pm_poweredby = $_POST['pm_poweredby']; 73 if($pm_poweredby): 74 $pm_poweredby = 1; 75 else: 76 $pm_poweredby = 0; 77 endif; 78 79 $pm_trackopens = $_POST['pm_trackopens']; 80 if($pm_trackopens){ 81 $pm_trackopens = 1; 82 $pm_forcehtml = 1; 83 } 84 else 85 { 86 $pm_trackopens = 0; 87 } 22 $this->settings = $this->load_settings(); 23 } 88 24 89 25 90 update_option('postmark_enabled', $pm_enabled); 91 update_option('postmark_api_key', $api_key); 92 update_option('postmark_sender_address', $sender_email); 93 update_option('postmark_force_html', $pm_forcehtml); 94 update_option('postmark_poweredby', $pm_poweredby); 95 update_option('postmark_trackopens', $pm_trackopens); 26 function init() { 27 if ( ! current_user_can( 'manage_options' ) ) { 28 return; 29 } 96 30 97 $msg_updated = "Postmark settings have been saved."; 98 } 99 ?> 31 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 32 add_action( 'wp_ajax_postmark_save', array( $this, 'save_settings' ) ); 33 add_action( 'wp_ajax_postmark_test', array( $this, 'send_test_email' ) ); 34 } 100 35 101 <script type="text/javascript" >102 jQuery(document).ready(function($) {103 36 104 $("#test-form").submit(function(e){ 105 e.preventDefault(); 106 var $this = $(this); 107 var send_to = $('#pm_test_address').val(); 37 function load_settings() { 38 $settings = get_option( 'postmark_settings' ); 108 39 109 $("#test-form .button-primary").val("Sending…"); 110 $.post(ajaxurl, {email: send_to, action:$this.attr("action")}, function(data){ 111 $("#test-form .button-primary").val(data); 112 }); 113 }); 40 if ( false === $settings ) { 41 $settings = array( 42 'enabled' => get_option( 'postmark_enabled', 0 ), 43 'api_key' => get_option( 'postmark_api_key', '' ), 44 'sender_address' => get_option( 'postmark_sender_address', '' ), 45 'force_html' => get_option( 'postmark_force_html', 0 ), 46 'track_opens' => get_option( 'postmark_trackopens', 0 ) 47 ); 114 48 115 }); 116 </script> 49 update_option( 'postmark_settings', json_encode( $settings ) ); 117 50 118 <div class="wrap"> 51 return $settings; 52 } 119 53 120 <?php if (isset($msg_updated)): ?><div class="updated"><p><?php echo $msg_updated; ?></p></div><?php endif; ?> 121 <?php if (isset($msg_error)): ?><div class="error"><p><?php echo $msg_error; ?></p></div><?php endif; ?> 54 return json_decode( $settings, true ); 55 } 122 56 123 <div id="icon-tools" class="icon32"></div>124 <h2><img src="<?php echo WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)) ?>images/PM-Logo.jpg" /></h2>125 <h3>What is Postmark?</h3>126 <p>This Postmark Approved plugin enables WordPress blogs of any size to deliver and track WordPress notification emails reliably, with minimal setup time and zero maintenance. </p>127 <p>If you don't already have a free Postmark account, <a href="https://postmarkapp.com/sign_up">you can get one in minutes</a>. Every account comes with 1000 free sends.</p>128 57 129 <br /> 58 function admin_menu() { 59 add_options_page( 'Postmark', 'Postmark', 'manage_options', 'pm_admin', array( $this, 'settings_html' ) ); 60 } 130 61 131 <h3>Your Postmark Settings</h3>132 <form method="post" action="options-general.php?page=pm_admin">133 <table class="form-table">134 <tbody>135 <tr>136 <th><label for="pm_enabled">Send using Postmark</label></th>137 <td><input name="pm_enabled" id="" type="checkbox" value="1"<?php if(get_option('postmark_enabled') == 1): echo ' checked="checked"'; endif; ?>/> <span style="font-size:11px;">Sends emails sent using wp_mail via Postmark.</span></td>138 </tr>139 <tr>140 <th><label for="pm_api_key">Postmark API Key</label></th>141 <td><input name="pm_api_key" id="" type="text" value="<?php echo get_option('postmark_api_key'); ?>" class="regular-text"/> <br/><span style="font-size:11px;">Your API key is available in the <strong>credentials</strong> screen of your Postmark server. <a href="https://postmarkapp.com/servers/">Create a new server in Postmark</a>.</span></td>142 </tr>143 <tr>144 <th><label for="pm_sender_address">Sender Email Address</label></th>145 <td><input name="pm_sender_address" id="" type="text" value="<?php echo get_option('postmark_sender_address'); ?>" class="regular-text"/> <br/><span style="font-size:11px;">This email needs to be one of your <strong>verified sender signatures</strong>. <br/>It will appear as the "from" email on all outbound messages. <a href="https://postmarkapp.com/signatures">Set one up in Postmark</a>.</span></td>146 </tr>147 <tr>148 <th><label for="pm_forcehtml">Force HTML</label></th>149 <td><input name="pm_forcehtml" id="" type="checkbox" value="1"<?php if(get_option('postmark_force_html') == 1): echo ' checked="checked"'; endif; ?>/> <span style="font-size:11px;">Force all emails to be sent as HTML.</span></td>150 </tr>151 <tr>152 <th><label for="pm_trackopens">Track Opens</label></th>153 <td><input name="pm_trackopens" id="" type="checkbox" value="1"<?php if(get_option('postmark_trackopens') == 1): echo ' checked="checked"'; endif; ?>/> <span style="font-size:11px;">Use Postmark's Open Tracking feature to capture open events. (Forces Html option to be turned on)</span></td>154 </tr>155 <tr>156 <th><label for="pm_poweredby">Support Postmark</label></th>157 <td><input name="pm_poweredby" id="" type="checkbox" value="1"<?php if(get_option('postmark_poweredby') == 1): echo ' checked="checked"'; endif; ?>/> <span style="font-size:11px;">Adds a credit to Postmark at the bottom of emails.</span></td>158 </tr>159 </tbody>160 </table>161 <div class="submit">162 <input type="submit" name="submit" value="Save" class="button-primary" />163 </div>164 </form>165 62 166 <br /> 63 function send_test_email() { 64 $to = $_POST['email']; 65 $subject = 'Postmark Test: ' . get_bloginfo( 'name' ); 66 $message = 'This is a <strong>test</strong> email sent using the Postmark plugin.'; 67 $response = wp_mail( $to, $subject, $message ); 68 echo ( false !== $response ) ? 'Test sent' : 'Test failed'; 69 wp_die(); 70 } 167 71 168 <h3>Test Postmark Sending</h3>169 <form method="post" id="test-form" action="pm_admin_test">170 <table class="form-table">171 <tbody>172 <tr>173 <th><label for="pm_test_address">Send a Test Email To</label></th>174 <td> <input name="pm_test_address" id="pm_test_address" type="text" value="<?php echo get_option('postmark_sender_address'); ?>" class="regular-text"/></td>175 </tr>176 </tbody>177 </table>178 <div class="submit">179 <input type="submit" name="submit" value="Send Test Email" class="button-primary" />180 </div>181 </form>182 72 183 <p style="margin-top:40px; padding-top:10px; border-top:1px solid #ddd;">This plugin is brought to you by <a href="http://www.postmarkapp.com">Postmark</a> & <a href="http://www.andydev.co.uk/">Andrew Yates</a>.</p> 73 function save_settings() { 74 $settings = stripslashes( $_POST['data'] ); 75 $json_test = json_decode( $settings, true ); 184 76 185 </div> 77 // Check for valid JSON 78 if ( isset( $json_test['enabled'] ) ) { 79 update_option( 'postmark_settings', $settings ); 80 echo 'Settings saved'; 81 } 82 else { 83 echo 'Error: invalid JSON'; 84 } 85 wp_die(); 86 } 186 87 187 <?php188 }189 88 190 add_action('wp_ajax_pm_admin_test', 'pm_admin_test_ajax'); 191 function pm_admin_test_ajax() { 192 $response = pm_send_test(); 193 194 echo $response; 195 196 die(); 197 } 198 199 // End Admin Functionality 200 201 // Override wp_mail() if postmark enabled 202 if(get_option('postmark_enabled') == 1){ 203 if (!function_exists("wp_mail")){ 204 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()) { 205 206 // Compact the input, apply the filters, and extract them back out 207 extract(apply_filters('wp_mail', compact('to', 'subject', 'message', 'headers', 'attachments'))); 208 209 $recognized_headers = pm_parse_headers($headers); 210 211 //Adding the filter thats executed in the wp_mail function so that plugins using those filters will not clash 212 //Did not used the filters wp_mail_from_name, wp_mail_from(both are defined in the postmarkapp settings) and wp_mail_charset(postmarkapp does not accept charset) 213 $recognized_headers['Content-Type'] = apply_filters( 'wp_mail_content_type', $recognized_headers['Content-Type'] ); 214 215 if (isset($recognized_headers['Content-Type']) && stripos($recognized_headers['Content-Type'], 'text/html') !== false) { 216 $current_email_type = 'HTML'; 217 } else { 218 $current_email_type = 'PLAINTEXT'; 219 } 220 221 // Define Headers 222 $postmark_headers = array( 223 'Accept' => 'application/json', 224 'Content-Type' => 'application/json', 225 'X-Postmark-Server-Token' => get_option('postmark_api_key') 226 ); 227 228 // If "Support Postmark" is on 229 if(get_option('postmark_poweredby') == 1){ 230 // Check Content Type 231 if(!strpos($headers, "text/html")){ 232 $message .= "\n\nPostmark solves your WordPress email problems. Send transactional email confidently using http://postmarkapp.com"; 233 } 234 } 235 236 // Send Email 237 if (is_array($to)) { 238 $recipients = implode(",", $to); 239 } else { 240 $recipients = $to; 241 } 242 243 // Construct Message 244 $email = array(); 245 $email['To'] = $recipients; 246 $email['From'] = get_option('postmark_sender_address'); 247 $email['Subject'] = $subject; 248 $email['TextBody'] = $message; 249 250 if (isset($recognized_headers['Cc']) && !empty($recognized_headers['Cc'])) { 251 $email['Cc'] = $recognized_headers['Cc']; 252 } 253 254 if (isset($recognized_headers['Bcc']) && !empty($recognized_headers['Bcc'])) { 255 $email['Bcc'] = $recognized_headers['Bcc']; 256 } 257 258 if (isset($recognized_headers['Reply-To']) && !empty($recognized_headers['Reply-To'])) { 259 $email['ReplyTo'] = $recognized_headers['Reply-To']; 260 } 261 262 if ($current_email_type == 'HTML') { 263 $email['HtmlBody'] = $message; 264 } else if (get_option('postmark_force_html') == 1 || get_option('postmark_trackopens') == 1) { 265 $email['HtmlBody'] = pm_convert_plaintext_to_html($message); 266 } 267 268 if (get_option('postmark_trackopens') == 1) { 269 $email['TrackOpens'] = "true"; 270 } 271 272 $response = pm_send_mail($postmark_headers, $email); 273 274 if (is_wp_error($response)) { 275 return false; 276 } 277 return true; 278 } 279 } 280 } 281 282 function pm_convert_plaintext_to_html($message) { 283 $message = nl2br(htmlspecialchars($message)); 284 return $message; 285 } 286 287 function pm_parse_headers($headers) { 288 if (!is_array($headers)) { 289 if (stripos($headers, "\r\n") !== false) { 290 $headers = explode("\r\n", $headers); 291 } else { 292 $headers = explode("\n", $headers); 293 } 89 function settings_html() { 90 include( POSTMARK_DIR . '/page-settings.php' ); 294 91 } 295 $recognized_headers = array();296 $headers_list = array(297 'Content-Type' => array(),298 'Bcc' => array(),299 'Cc' => array(),300 'Reply-To' => array()301 );302 $headers_list_lowercase = array_change_key_case($headers_list, CASE_LOWER);303 if (!empty($headers)) {304 foreach ($headers as $key => $header) {305 $key = strtolower($key);306 if (array_key_exists($key, $headers_list_lowercase)) {307 $header_key = $key;308 $header_val = $header;309 $segments = explode(':', $header);310 if (count($segments) === 2) {311 if (array_key_exists(strtolower($segments[0]), $headers_list_lowercase)) {312 list($header_key, $header_val) = $segments;313 $header_key = strtolower($header_key);314 }315 }316 }317 else {318 $segments = explode(':', $header);319 if (count($segments) === 2) {320 if (array_key_exists(strtolower($segments[0]), $headers_list_lowercase)) {321 list($header_key, $header_val) = $segments;322 $header_key = strtolower($header_key);323 }324 }325 }326 if (isset($header_key) && isset($header_val)) {327 if (stripos($header_val, ',') === false) {328 $headers_list_lowercase[$header_key][] = trim($header_val);329 }330 else {331 $vals = explode(',', $header_val);332 foreach ($vals as $val) {333 $headers_list_lowercase[$header_key][] = trim($val);334 }335 }336 unset($header_key);337 unset($header_val);338 }339 }340 341 foreach ($headers_list as $key => $value) {342 $value = $headers_list_lowercase[strtolower($key)];343 if (count($value) > 0) {344 $recognized_headers[$key] = implode(', ', $value);345 }346 }347 }348 return $recognized_headers;349 }350 351 function pm_send_test(){352 $email_address = $_POST['email'];353 354 // Define Headers355 $postmark_headers = array(356 'Accept' => 'application/json',357 'Content-Type' => 'application/json',358 'X-Postmark-Server-Token' => get_option('postmark_api_key')359 );360 361 $message = 'This is a test email sent via Postmark from '.get_bloginfo('name').'.';362 $html_message = 'This is a test email sent via <strong>Postmark</strong> from '.get_bloginfo('name').'.';363 364 if(get_option('postmark_poweredby') == 1){365 $message .= "\n\nPostmark solves your WordPress email problems. Send transactional email confidently using http://postmarkapp.com";366 $html_message .= '<br /><br />Postmark solves your WordPress email problems. Send transactional email confidently using <a href="http://postmarkapp.com">Postmark</a>.';367 }368 369 $email = array();370 $email['To'] = $email_address;371 $email['From'] = get_option('postmark_sender_address');372 $email['Subject'] = get_bloginfo('name').' Postmark Test';373 $email['TextBody'] = $message;374 375 if(get_option('postmark_force_html') == 1){376 $email['HtmlBody'] = $html_message;377 }378 379 if(get_option('postmark_trackopens') == 1){380 $email['TrackOpens'] = "true";381 }382 383 $response = pm_send_mail($postmark_headers, $email);384 385 if ($response === false){386 return "Test Failed with Error ".curl_error($curl);387 } else {388 return "Test Sent";389 }390 391 die();392 92 } 393 93 394 94 395 function pm_send_mail($headers, $email){ 396 $args = array( 397 'headers' => $headers, 398 'body' => json_encode($email) 399 ); 400 $response = wp_remote_post(POSTMARK_ENDPOINT, $args); 95 if ( ! function_exists( 'wp_mail' ) ) { 96 $postmark = new Postmark_Mail(); 401 97 402 if($response['response']['code'] == 200) { 403 return true; 404 } else { 405 return false; 406 } 98 if ( 1 == $postmark->settings['enabled'] ) { 99 include( POSTMARK_DIR . '/wp-mail.php' ); 100 } 407 101 } 408 409 ?> -
postmark-approved-wordpress-plugin/trunk/readme.txt
r1233123 r1364176 1 1 === Postmark Approved WordPress Plugin === 2 Contributors: andy7629, alexknowshtml, jptoto2 Contributors: andy7629, alexknowshtml, mgibbs189, jptoto 3 3 Tags: postmark, email, smtp, notifications, wp_mail, wildbit 4 Requires at least: 3.25 Tested up to: 4. 34 Requires at least: 4.0 5 Tested up to: 4.4 6 6 Stable tag: trunk 7 7 … … 12 12 If you're still sending email with default SMTP, you're blind to delivery problems! This Postmark Approved WordPress Plugin enables WordPress blogs of any size to deliver and track WordPress notification emails reliably, with minimal setup time and zero maintenance. No more SMTP errors or delivery problems with Postmark! 13 13 14 If you don't already have a free Postmark account, you can get one in minutes. Every account comes with 10,000 free sends.14 If you don't already have a free Postmark account, you can get one in minutes. Every account comes with 25,000 free credits. 15 15 16 16 == Installation == … … 34 34 = Does this cost me money? = 35 35 36 This Postmark plugin is 100% free. All new Postmark accounts include 1000 free email sends. Beyond your first 1000 email sends, they will cost only $1.50 per 1000 sends with no monthly commitments and no expirations.36 This Postmark plugin is 100% free. All new Postmark accounts include 25,000 free credits. Afterwards, they will cost only $1.50 per 1000 sends with no monthly commitments and no expirations. 37 37 38 38 We will send you multiple warnings as you approach running out of send credits, so you don't need to worry about paying for credits until you absolutely need them. 39 39 40 Sign up for your free Postmark account at http ://postmarkapp.comand get started now.40 Sign up for your free Postmark account at https://postmarkapp.com/ and get started now. 41 41 42 42 = My emails are still not sending, or they are going to spam! HELP!? = … … 61 61 62 62 == Changelog == 63 = v1.8 = 64 * Modernization of codebase. 65 63 66 = v1.7 = 64 67 * Support headers for cc, bcc, and reply-to
Note: See TracChangeset
for help on using the changeset viewer.