Plugin Directory

Changeset 1364176


Ignore:
Timestamp:
03/04/2016 04:00:03 PM (10 years ago)
Author:
atheken
Message:

Updating plugin to 1.8

Location:
postmark-approved-wordpress-plugin/trunk
Files:
4 added
3 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • postmark-approved-wordpress-plugin/trunk/postmark.php

    r1233123 r1364176  
    11<?php
    22/*
    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
     3Plugin Name: Postmark (Official)
     4Plugin URI: https://postmarkapp.com/
     5Description: Overwrites wp_mail to send emails through Postmark
     6Version: 1.8
     7Author: Andrew Yates & Matt Gibbs
    268*/
    279
    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);
     10class Postmark_Mail
     11{
     12    public $settings;
    5113
    5214
    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 ) ) );
    6119
    62         $api_key = $_POST['pm_api_key'];
    63         $sender_email = $_POST['pm_sender_address'];
     20        add_filter( 'init', array( $this, 'init' ) );
    6421
    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    }
    8824
    8925
    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        }
    9630
    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    }
    10035
    101     <script type="text/javascript" >
    102     jQuery(document).ready(function($) {
    10336
    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' );
    10839
    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            );
    11448
    115     });
    116     </script>
     49            update_option( 'postmark_settings', json_encode( $settings ) );
    11750
    118     <div class="wrap">
     51            return $settings;
     52        }
    11953
    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    }
    12256
    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>
    12857
    129         <br />
     58    function admin_menu() {
     59        add_options_page( 'Postmark', 'Postmark', 'manage_options', 'pm_admin', array( $this, 'settings_html' ) );
     60    }
    13061
    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>
    16562
    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    }
    16771
    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>
    18272
    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> &amp; <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 );
    18476
    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    }
    18687
    187 <?php
    188 }
    18988
    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' );
    29491    }
    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 Headers
    355     $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();
    39292}
    39393
    39494
    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);
     95if ( ! function_exists( 'wp_mail' ) ) {
     96    $postmark = new Postmark_Mail();
    40197
    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    }
    407101}
    408 
    409 ?>
  • postmark-approved-wordpress-plugin/trunk/readme.txt

    r1233123 r1364176  
    11=== Postmark Approved WordPress Plugin ===
    2 Contributors: andy7629, alexknowshtml, jptoto
     2Contributors: andy7629, alexknowshtml, mgibbs189, jptoto
    33Tags: postmark, email, smtp, notifications, wp_mail, wildbit
    4 Requires at least: 3.2
    5 Tested up to: 4.3
     4Requires at least: 4.0
     5Tested up to: 4.4
    66Stable tag: trunk
    77
     
    1212If 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!
    1313
    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.
     14If you don't already have a free Postmark account, you can get one in minutes. Every account comes with 25,000 free credits.
    1515
    1616== Installation ==
     
    3434= Does this cost me money? =
    3535
    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.
     36This 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.
    3737
    3838We 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.
    3939
    40 Sign up for your free Postmark account at http://postmarkapp.com and get started now.
     40Sign up for your free Postmark account at https://postmarkapp.com/ and get started now.
    4141
    4242= My emails are still not sending, or they are going to spam! HELP!? =
     
    6161
    6262== Changelog ==
     63= v1.8 =
     64* Modernization of codebase.
     65
    6366= v1.7 =
    6467* Support headers for cc, bcc, and reply-to
Note: See TracChangeset for help on using the changeset viewer.