WordPress.org

Plugin Directory

Changeset 1469692


Ignore:
Timestamp:
08/08/16 01:14:27 (16 months ago)
Author:
jbrinley
Message:

Version 1.1.1 - subscription management

Location:
mailgun-subscriptions/trunk
Files:
9 added
13 edited

Legend:

Unmodified
Added
Removed
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/API.php

    r994371 r1469692  
    88    private $key = ''; 
    99    private $url = ''; 
    10     public function __construct( $apiKey, $apiEndpoint = "api.mailgun.net", $apiVersion = "v2", $ssl = true ) { 
     10    public function __construct( $apiKey, $apiEndpoint = "api.mailgun.net", $apiVersion = "v3", $ssl = true ) { 
    1111        $this->key = $apiKey; 
    1212        $this->url = $this->build_base_url( $apiEndpoint, $apiVersion, $ssl ); 
     
    4545    } 
    4646 
     47    public function put( $endpoint, $args = array() ) { 
     48        $url = $this->url . $endpoint; 
     49        $response = wp_remote_request( 
     50            $url, 
     51            array( 
     52                'body' => $args, 
     53                'headers' => $this->get_request_headers(), 
     54                'method' => 'PUT', 
     55            ) 
     56        ); 
     57        if ( is_wp_error($response) ) { 
     58            return FALSE; 
     59        } 
     60        $response['body'] = json_decode($response['body']); 
     61        return $response; 
     62    } 
     63 
     64    public function delete( $endpoint, $args = array() ) { 
     65        $url = $this->url . $endpoint; 
     66        $response = wp_remote_request( 
     67            $url, 
     68            array( 
     69                'body' => $args, 
     70                'headers' => $this->get_request_headers(), 
     71                'method' => 'DELETE', 
     72            ) 
     73        ); 
     74        if ( is_wp_error($response) ) { 
     75            return FALSE; 
     76        } 
     77        $response['body'] = json_decode($response['body']); 
     78        return $response; 
     79    } 
     80 
    4781    public function validate_email( $address ) { 
    4882        $response = $this->get( 'address/validate', array( 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Admin_Page.php

    r994371 r1469692  
    88class Admin_Page { 
    99    const MENU_SLUG = 'mailgun_subscriptions'; 
     10    const OPTION_ACCOUNT_PAGE = 'mailgun_account_management_page'; 
    1011 
    1112    public function refresh_caches() { 
     
    150151        ); 
    151152 
     153        add_settings_field( 
     154            'mailgun_token_email_template', 
     155            __('Account Management Email', 'mailgun-subscriptions'), 
     156            array( $this, 'display_textarea_field' ), 
     157            self::MENU_SLUG, 
     158            'confirmation', 
     159            array( 
     160                'option' => 'mailgun_token_email_template', 
     161                'description' => $this->get_token_email_field_description(), 
     162                'default' => Template::token_email(), 
     163            ) 
     164        ); 
     165 
     166        register_setting( 
     167            self::MENU_SLUG, 
     168            'mailgun_token_email_template' 
     169        ); 
     170 
    152171        register_setting( 
    153172            self::MENU_SLUG, 
     
    159178            'mailgun_new_list', 
    160179            array( $this, 'save_new_list' ) 
     180        ); 
     181 
     182        add_settings_section( 
     183            'account_management', 
     184            __('Account Management', 'mailgun-subscriptions'), 
     185            '__return_false', 
     186            self::MENU_SLUG 
     187        ); 
     188 
     189        add_settings_field( 
     190            self::OPTION_ACCOUNT_PAGE, 
     191            __('Account Management Page', 'mailgun-subscriptions'), 
     192            array( $this, 'display_page_select_field' ), 
     193            self::MENU_SLUG, 
     194            'account_management', 
     195            array( 
     196                'option' => self::OPTION_ACCOUNT_PAGE, 
     197                'description' => $this->get_account_management_page_description(), 
     198                'default' => 0, 
     199            ) 
    161200        ); 
    162201    } 
     
    199238        $value = get_option( $args['option'], $args['default'] ); 
    200239        printf( '<textarea rows="%s" cols="%s" name="%s" class="widefat">%s</textarea>', intval($args['rows']), intval($args['cols']), esc_attr($args['option']), esc_textarea($value) ); 
     240        if ( !empty($args['description']) ) { 
     241            printf( '<p class="description">%s</p>', $args['description'] ); 
     242        } 
     243    } 
     244 
     245    public function display_page_select_field( $args ) { 
     246        if ( !isset($args['option']) ) { 
     247            return; 
     248        } 
     249        $args = wp_parse_args( $args, array('default' => 0, 'description' => '' ) ); 
     250        $value = get_option( $args['option'], $args['default'] ); 
     251        wp_dropdown_pages( array( 
     252            'selected' => $value, 
     253            'name' => $args[ 'option' ], 
     254            'show_option_none' => false, 
     255        )); 
    201256        if ( !empty($args['description']) ) { 
    202257            printf( '<p class="description">%s</p>', $args['description'] ); 
     
    359414        $description = __("This email will be sent to users after they confirm their subscription. Leave blank to disable this email. Your template can contain the following shortcodes:<br /> 
    360415            <code>[email]</code> &ndash; This is the user's email address.<br /> 
    361             <code>[lists]</code> &ndash; This is a list of the lists the user opted to subscribe to.", 'mailgun-subscriptions' ); 
     416            <code>[lists]</code> &ndash; This is a list of the lists the user opted to subscribe to.<br /> 
     417            <code>[link]</code> &ndash; This is the URL to the user's account management page.", 'mailgun-subscriptions' ); 
    362418        return $description; 
     419    } 
     420 
     421    public function get_token_email_field_description() { 
     422        $description = __("This email will be sent to users when they request a link to their account management page. Your template can contain the following shortcodes:<br /> 
     423            <code>[link]</code> &ndash; This is the URL to the user's account management page.", 'mailgun-subscriptions' ); 
     424        return $description; 
     425    } 
     426 
     427    public function get_account_management_page_description() { 
     428        return __( 'Select which Page of your site will be used to display the Account Management page', 'mailgun-subscriptions' ); 
    363429    } 
    364430} 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Confirmation_Handler.php

    r994371 r1469692  
    9999        $message = str_replace( '[email]', $this->confirmation->get_address(), $message ); 
    100100        $message = str_replace( '[lists]', $this->get_formatted_lists(), $message ); 
     101        $message = str_replace( '[link]', esc_url_raw( $this->get_account_management_url( $this->confirmation->get_address() ) ), $message ); 
    101102        return $message; 
    102103    } 
     
    117118        } 
    118119        return apply_filters( 'mailgun_welcome_email_lists', implode("\n", $formatted), $requested_lists ); 
     120    } 
     121 
     122    protected function get_account_management_url( $email_address ) { 
     123        $token_emailer = new Account_Management_Token_Email( $email_address ); 
     124        return $token_emailer->get_token_link(); 
    119125    } 
    120126 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Plugin.php

    r994371 r1469692  
    66 
    77class Plugin { 
    8     const VERSION = '1.0'; 
     8    const VERSION = '1.1.1'; 
    99 
    1010    /** @var Plugin */ 
     
    2424    /** @var Shortcode_Handler */ 
    2525    private $shortcode_handler = NULL; 
     26 
     27    /** @var Account_Management_Page */ 
     28    private $account_management_page = NULL; 
     29 
     30    /** @var Account_Management_Token_Request_Handler */ 
     31    private $token_request_handler = NULL; 
     32 
     33    /** @var Account_Management_Subscription_Request_Handler */ 
     34    private $account_manangement_subscription_handler = NULL; 
    2635 
    2736    public function api( $public = FALSE ) { 
     
    4958    } 
    5059 
     60    public function account_management_page() { 
     61        return $this->account_management_page; 
     62    } 
     63 
     64    public function token_request_handler() { 
     65        return $this->token_request_handler; 
     66    } 
     67 
    5168    private function setup( $plugin_file ) { 
    5269        self::$plugin_file = $plugin_file; 
     
    6077 
    6178        if ( !is_admin() ) { 
    62             if ( !empty($_POST['mailgun-action']) && $_POST['mailgun-action'] == 'subscribe' ) { 
    63                 $this->setup_submission_handler(); 
     79            if ( !empty( $_REQUEST[ 'mailgun-action' ] ) ) { 
     80                switch( $_REQUEST[ 'mailgun-action' ] ) { 
     81                    case 'subscribe': 
     82                        $this->setup_submission_handler(); 
     83                        break; 
     84                    case 'confirm': 
     85                        $this->setup_confirmation_handler(); 
     86                        break; 
     87                    case 'request-token': 
     88                        $this->setup_token_request_handler(); 
     89                        break; 
     90                    case 'account-subscribe': 
     91                    case 'account-resubscribe': 
     92                    case 'account-unsubscribe': 
     93                        $this->setup_account_management_handler(); 
     94                        break; 
     95                } 
    6496            } 
    65             if ( !empty($_GET['mailgun-action']) && $_GET['mailgun-action'] == 'confirm' ) { 
    66                 $this->setup_confirmation_handler(); 
    67             } 
    68  
    6997            add_action( 'wp', array( $this, 'setup_confirmation_page' ), 10, 0 ); 
    7098        } 
     
    76104        $this->setup_widget(); 
    77105        $this->setup_shortcodes(); 
     106        $this->setup_account_management_page(); 
    78107        add_action( 'mailgun_enqueue_assets', array( $this, 'enqueue_assets' ), 10, 0 ); 
    79108    } 
     
    127156        $this->shortcode_handler = new Shortcode_Handler(); 
    128157        $this->shortcode_handler->register_shortcodes(); 
     158    } 
     159 
     160    public function setup_account_management_page() { 
     161        $this->account_management_page = new Account_Management_Page( new Account_Management_Page_Authenticator( $_COOKIE ) ); 
     162        add_action( 'init', array( $this->account_management_page, 'init' ) ); 
     163    } 
     164 
     165    public function setup_token_request_handler() { 
     166        $this->token_request_handler = new Account_Management_Token_Request_Handler( $_POST ); 
     167        add_action( 'parse_request', array( $this->token_request_handler, 'handle_request' ), 10, 0 ); 
     168    } 
     169 
     170    public function setup_account_management_handler() { 
     171        $this->account_manangement_subscription_handler = new Account_Management_Subscription_Request_Handler( $_GET, new Account_Management_Page_Authenticator( $_COOKIE ) ); 
     172        add_action( 'parse_request', array( $this->account_manangement_subscription_handler, 'handle_request' ), 10, 0 ); 
    129173    } 
    130174 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Shortcode_Handler.php

    r994371 r1469692  
    1010        add_shortcode( 'mailgun_lists', array( $this, 'lists_shortcode' ) ); 
    1111        add_shortcode( 'mailgun_subscription_form', array( $this, 'form_shortcode' ) ); 
     12        add_shortcode( Account_Management_Page::SHORTCODE, array( $this, 'account_management_shortcode' ) ); 
    1213    } 
    1314 
     
    8586        return array_keys($lists); 
    8687    } 
     88 
     89    public function account_management_shortcode( $atts, $content = '', $tag = '' ) { 
     90        $page = Plugin::instance()->account_management_page(); 
     91        return $page->get_page_contents(); 
     92    } 
    8793}  
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Submission_Handler.php

    r994371 r1469692  
    186186    protected function get_redirect_base_url() { 
    187187        $url = $_SERVER['REQUEST_URI']; 
    188         foreach ( array('mailgun-message', 'mailgun-error', 'mailgun-action', 'ref') as $key ) { 
    189             $url = remove_query_arg('key', $url); 
     188        foreach ( array('mailgun-message', 'mailgun-error', 'mailgun-action', 'ref', 'list', 'nonce') as $key ) { 
     189            $url = remove_query_arg( $key, $url ); 
    190190        } 
    191191        return $url; 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Subscription_Form.php

    r994371 r1469692  
    7171                break; 
    7272            default: 
    73                 $message = $code; 
     73                $message = ''; 
    7474                break; 
    7575        } 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Template.php

    r994371 r1469692  
    1111 
    1212    public static function welcome_email() { 
    13         return __("Your email address, [email], has been confirmed. You are now subscribed to the following lists:\n\n[lists]", 'mailgun-subscriptions'); 
     13        return __("Your email address, [email], has been confirmed. You are now subscribed to the following lists:\n\n[lists]\n\nTo manage your subscriptions, visit:\n\n[link]", 'mailgun-subscriptions'); 
    1414    } 
    1515 
     
    1717        return __("<p>Thank you for confirming your subscription. <strong>[mailgun_email]</strong> is now subscribed to:</p>[mailgun_lists]", 'mailgun-subscriptions'); 
    1818    } 
     19 
     20    public static function token_email() { 
     21        return __( "To manage your subscriptions, visit:\n\n[link]", 'mailgun-subscriptions' ); 
     22    } 
    1923} 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Widget.php

    r994371 r1469692  
    3838            'lists' => $instance['lists'], 
    3939        )); 
     40 
     41        if ( apply_filters( 'mailgun_subscriptions_widget_show_account_link', true ) ) { 
     42            $account_management_page = Plugin::instance()->account_management_page(); 
     43            $link = $account_management_page->get_page_url(); 
     44            if ( $link ) { 
     45                printf( '<p><a href="%s">%s</a></p>', esc_url( $link ), __( 'Manage your subscriptions', 'mailgun-subscriptions' ) ); 
     46            } 
     47        } 
    4048 
    4149        echo $args['after_widget']; 
  • mailgun-subscriptions/trunk/assets/mailgun-subscriptions.css

    r994371 r1469692  
    2323    color: #CC0000; 
    2424} 
     25 
     26.mailgun-subscription-account-management .mailgun-subscription-details { 
     27    margin: 0 0 1em; 
     28} 
     29.mailgun-subscription-account-management .mailgun-subscription-details h3 { 
     30    margin: 0 0 0.25em; 
     31} 
     32.mailgun-subscription-account-management .mailgun-subscription-details p { 
     33    margin: 0; 
     34    padding-left: 1em; 
     35} 
     36.mailgun-subscription-account-management .mailgun-subscription-details p.current-status { 
     37    padding-left: 0; 
     38} 
     39.mailgun-subscription-account-management .mailgun-subscription-details p.current-status::before { 
     40    display: inline-block; 
     41    width: .8em; 
     42    font-size: 1.25em; 
     43    line-height: 1.2; 
     44    position: relative; 
     45    top: 1px; 
     46} 
     47.mailgun-subscription-account-management .mailgun-subscription-details p.subscribe.current-status::before { 
     48    content: '\2713'; /* check mark */ 
     49    color: #23b225; 
     50} 
     51.mailgun-subscription-account-management .mailgun-subscription-details p.unsubscribe.current-status::before { 
     52    content: '\2717'; /* box with x */ 
     53    color: #d42626; 
     54} 
  • mailgun-subscriptions/trunk/mailgun-subscriptions.php

    r994371 r1469692  
    66Author: Flightless 
    77Author URI: http://flightless.us/ 
    8 Version: 1.0 
     8Version: 1.1.1 
    99Text Domain: mailgun-subscriptions 
    1010Domain Path: /languages 
  • mailgun-subscriptions/trunk/readme.md

    r994371 r1469692  
    88 
    99You'll find the "Mailgun Lists" settings page in the Settings admin menu. Here, you can setup your API keys, control which lists you're making available, and create custom descriptions for your lists. 
     10 
     11When the plugin is activated, the "Subscription Management" page will be automatically created for you. You can customize the title of this page, or set it to a different page using the option on the settings screen. If you accidentally delete the page, a new one will be created for you. 
    1012 
    1113## Subscription Form Widget 
     
    3638### Confirmation Email 
    3739 
    38 You can set up templates for two emails the plugin will send. 
     40You can set up templates for three emails the plugin will send. 
    3941 
    4042When a user first submits the subscription form, the "Confirmation Email" is sent. Your template should contain the following shortcodes: 
     
    5860* `[email]` - This is the user's email address. 
    5961* `[lists]` - This is a list of the lists the user opted to subscribe to. 
     62* `[link]`  - This is the unique URL to the user's account management page. 
    6063 
    6164#### Filters 
     
    6669 
    6770`mailgun_welcome_email_lists` - Edit the list of mailing lists in the email template. 
     71 
     72### Account Management Email 
     73 
     74When a user requests access to the account management page, they will receive this email. This template can include: 
     75 
     76* `[link]`  - This is the unique URL to the user's account management page. 
     77 
     78#### Filters 
     79 
     80`mailgun_token_email_subject` - Edit the subject of the welcome email. 
     81 
     82`mailgun_token_email_template` - Edit the account management email template. 
    6883 
    6984## Confirmation Page 
  • mailgun-subscriptions/trunk/readme.txt

    r994371 r1469692  
    33Tags: mailing lists, subscriptions, widget, email 
    44Requires at least: 3.9 
    5 Tested up to: 3.9 
    6 Stable tag: 1.0 
     5Tested up to: 4.6 
     6Stable tag: 1.1.1 
    77License: BSD 3-Clause 
    88License URI: http://opensource.org/licenses/BSD-3-Clause 
     
    2121== Changelog == 
    2222 
     23= 1.1 = 
     24 
     25* New feature: subscription management 
     26 
    2327= 1.0 = 
    2428* Initial version 
Note: See TracChangeset for help on using the changeset viewer.