WordPress.org

Plugin Directory

Changeset 1703146


Ignore:
Timestamp:
07/26/17 13:59:08 (4 months ago)
Author:
jbrinley
Message:

Version 1.2.0

Location:
mailgun-subscriptions/trunk
Files:
14 edited

Legend:

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

    r1469692 r1703146  
    2424            switch ( $this->action ) { 
    2525                case 'account-subscribe': 
    26                     $this->handle_subscribe_request( $this->authenticator->get_email(), $this->submission[ 'list' ] ); 
     26                    $this->handle_subscribe_request( $this->authenticator->get_email(), $this->submission[ 'list' ], $this->submission[ 'name' ] ); 
    2727                    break; 
    2828                case 'account-unsubscribe': 
     
    3939    } 
    4040 
    41     private function handle_subscribe_request( $email_address, $list_address ) { 
     41    private function handle_subscribe_request( $email_address, $list_address, $name = '' ) { 
    4242        $submission_handler = new Submission_Handler( array( 
    4343            'mailgun-lists' => array( $list_address ), 
    4444            'mailgun-subscriber-email' => $email_address, 
     45            'mailgun-subscriber-name' => $name, 
    4546        )); 
    4647        $submission_handler->handle_request(); 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Account_Management_Token_Request_Handler.php

    r1469692 r1703146  
    4343 
    4444    private function is_valid_email( $email_address ) { 
    45         $api = Plugin::instance()->api( true ); 
    46         return (bool) ( $api->validate_email( $email_address ) ); 
     45        if ( apply_filters( 'mailgun_subscriptions_validate_email_with_api', false ) ) { 
     46            $valid = Plugin::instance()->api( TRUE )->validate_email( $email_address ); 
     47        } else { 
     48            $valid = is_email( $email_address ); 
     49        } 
     50        return (bool) $valid; 
    4751    } 
    4852 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Admin_Page.php

    r1489834 r1703146  
    343343        $lists = $this->get_mailing_lists_from_cache(); 
    344344        $addresses = wp_list_pluck( $lists, 'address' ); 
    345         $saved = get_option('mailgun_lists'); 
     345        $saved = (array) get_option('mailgun_lists'); 
    346346        $gone = array_diff( array_keys($saved), $addresses ); 
    347347        if ( !empty($gone) ) { 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Confirmation.php

    r994371 r1703146  
    1111    protected $post_id = ''; 
    1212    protected $address = ''; 
     13    protected $name = ''; 
    1314    protected $confirmed = FALSE; 
    1415    protected $lists = array(); 
     
    4344    } 
    4445 
     46    /** 
     47     * @param string $name 
     48     */ 
     49    public function set_name( $name ) { 
     50        $this->name = $name; 
     51    } 
     52 
     53    /** 
     54     * @return string 
     55     */ 
     56    public function get_name() { 
     57        return $this->name; 
     58    } 
    4559 
    4660    public function save() { 
     
    5165                'post_status' => 'publish', 
    5266                'post_author' => 0, 
    53                 'post_title' => $this->id, 
     67                'post_title' => sprintf( '%s (%s)', get_post_type_object( static::POST_TYPE )->labels->singular_name, $this->id ), 
    5468                'post_name' => $this->id, 
    5569            )); 
     
    5771        delete_post_meta( $this->post_id, '_mailgun_subscriber_lists' ); 
    5872        update_post_meta( $this->post_id, '_mailgun_subscriber_address', $this->address ); 
     73        update_post_meta( $this->post_id, '_mailgun_subscriber_name', $this->name ); 
    5974        update_post_meta( $this->post_id, '_mailgun_subscription_confirmed', $this->confirmed ); 
    6075        foreach ( $this->lists as $list ) { 
     
    8297        $this->post_id = reset($results); 
    8398        $this->address = get_post_meta($this->post_id, '_mailgun_subscriber_address', true); 
     99        $this->name = get_post_meta($this->post_id, '_mailgun_subscriber_name', true); 
    84100        $this->lists = get_post_meta($this->post_id, '_mailgun_subscriber_lists', false); 
    85101        $this->confirmed = get_post_meta($this->post_id, '_mailgun_subscription_confirmed', true); 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Confirmation_Handler.php

    r1469692 r1703146  
    7070    protected function do_subscription() { 
    7171        $address = $this->confirmation->get_address(); 
     72        $name = $this->confirmation->get_name(); 
    7273        $lists = $this->confirmation->get_lists(); 
    7374        $api = Plugin::instance()->api(); 
     
    7576            $response = $api->post("lists/$list_address/members", array( 
    7677                'address' => $address, 
     78                'name' => $name, 
    7779                'upsert' => 'yes', 
    7880            )); 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Null_Confirmation.php

    r994371 r1703146  
    1515 
    1616    public function get_address() { 
     17        return ''; 
     18    } 
     19 
     20    public function set_name( $name ) { 
     21        // do nothing 
     22    } 
     23 
     24    public function get_name() { 
    1725        return ''; 
    1826    } 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Plugin.php

    r1489834 r1703146  
    66 
    77class Plugin { 
    8     const VERSION = '1.1.2'; 
     8    const VERSION = '1.2.0'; 
    99 
    1010    /** @var Plugin */ 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Shortcode_Handler.php

    r1469692 r1703146  
    6565            'description' => '', 
    6666            'lists' => '', 
     67            'name' => false, 
    6768        ), $atts); 
    6869        if ( empty($atts['lists']) ) { 
     
    7778            'description' => $atts['description'], 
    7879            'lists' => $lists, 
     80            'name' => wp_validate_boolean($atts['name']), 
    7981        )); 
    8082        return ob_get_clean(); 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Submission_Handler.php

    r1469692 r1703146  
    6060 
    6161    protected function is_valid_email( $address ) { 
    62         $valid = Plugin::instance()->api( TRUE )->validate_email( $address ); 
     62        if ( apply_filters( 'mailgun_subscriptions_validate_email_with_api', false ) ) { 
     63            $valid = Plugin::instance()->api( TRUE )->validate_email( $address ); 
     64        } else { 
     65            $valid = is_email( $address ); 
     66        } 
    6367        if ( !$valid ) { 
    6468            $this->error_details['invalid-email'][] = $address; 
     
    9296        $confirmation = new Confirmation(); 
    9397        $confirmation->set_address($this->get_submitted_address()); 
     98        $confirmation->set_name($this->get_submitted_name()); 
    9499        $confirmation->set_lists($this->get_submitted_lists()); 
    95100        $confirmation->save(); 
     
    100105        $address = isset($this->submission['mailgun-subscriber-email']) ? $this->submission['mailgun-subscriber-email'] : ''; 
    101106        return $address; 
     107    } 
     108 
     109    protected function get_submitted_name() { 
     110        $name = isset($this->submission['mailgun-subscriber-name']) ? $this->submission['mailgun-subscriber-name'] : ''; 
     111        return $name; 
    102112    } 
    103113 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Subscription_Form.php

    r1469692 r1703146  
    117117            echo '</p>'; 
    118118        } 
     119        if ( !empty($instance['name']) ) { 
     120            echo '<p class="full-name">'; 
     121            printf( '<label for="mailgun-full-name-%d">%s</label> ', $instance_counter, __('Full Name', 'mailgun-subscriptions') ); 
     122            printf( '<input type="text" name="mailgun-subscriber-name" size="20" id="mailgun-full-name-%d" required placeholder="%s" />', $instance_counter, __('Full Name', 'mailgun-subscriptions') ); 
     123            echo '</p>'; 
     124        } 
     125 
    119126        echo '<p class="email-address">'; 
    120127        printf( '<label for="mailgun-email-address-%d">%s</label> ', $instance_counter, __('Email Address', 'mailgun-subscriptions') ); 
     
    124131            $default_email = $user->user_email; 
    125132        } 
    126         printf( '<input type="text" value="%s" name="mailgun-subscriber-email" size="20" id="mailgun-email-address-%d" />', $default_email, $instance_counter ); 
     133        printf( '<input type="text" value="%s" name="mailgun-subscriber-email" size="20" id="mailgun-email-address-%d" required placeholder="%s" />', $default_email, $instance_counter, __('Email', 'mailgun-subscriptions') ); 
    127134        echo '</p>'; 
    128135        printf( '<p class="submit"><input type="submit" value="%s" /></p>', apply_filters( 'mailgun_subscription_form_button_label', __('Subscribe', 'mailgun-subscriptions') ) ); 
     
    169176        return $url; 
    170177    } 
    171 }  
     178} 
  • mailgun-subscriptions/trunk/Mailgun_Subscriptions/Widget.php

    r1469692 r1703146  
    3737            'description' => $content, 
    3838            'lists' => $instance['lists'], 
     39            'name' => isset($instance['name']), 
    3940        )); 
    4041 
     
    5152 
    5253    public function update( $new_instance, $old_instance ) { 
    53         $instance = $old_instance; 
     54        $instance = $new_instance; 
    5455        $instance['title'] = strip_tags($new_instance['title']); 
    55         $instance['content'] = $new_instance['content']; 
    56         $instance['lists'] = $new_instance['lists']; 
    5756        return $instance; 
    5857    } 
     
    8281            <textarea class="widefat" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>"><?php echo esc_textarea($content); ?></textarea></p> 
    8382 
    84         <p><label for="<?php echo $this->get_field_id('lists'); ?>"><?php _e('Options:', 'mailgun-subscriptions'); ?></label> 
     83        <p> 
     84        <input class="widefat" id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" type="checkbox" <?php checked(isset($instance['name']) && $instance['name'] === 'on'); ?> /> 
     85        <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Require name?', 'mailgun-subscriptions'); ?></label> 
     86        </p> 
     87 
     88        <p><label for="<?php echo $this->get_field_id('lists'); ?>"><?php _e('List Options:', 'mailgun-subscriptions'); ?></label> 
    8589            <ul> 
    8690                <?php foreach ( Plugin::instance()->get_lists('name') as $list_address => $list_settings ): ?> 
  • mailgun-subscriptions/trunk/mailgun-subscriptions.php

    r1489834 r1703146  
    66Author: Flightless 
    77Author URI: http://flightless.us/ 
    8 Version: 1.1.2 
     8Version: 1.2.0 
    99Text Domain: mailgun-subscriptions 
    1010Domain Path: /languages 
  • mailgun-subscriptions/trunk/readme.md

    r1469692 r1703146  
    1313## Subscription Form Widget 
    1414 
    15 The plugin creates a widget called "Mailgun List Subscription Form". It includes options to set the title, an optional description, and the mailing lists that will be available in the widget. 
     15The plugin creates a widget called "Mailgun List Subscription Form". It includes options to set the title, an optional description, whether or not to require the user's name, and the mailing lists that will be available in the widget. 
    1616 
    1717## Shortcode 
     
    2121* `lists` - The email addresses of the lists that should be available in the form. 
    2222* `description` - The description that will display above the form. 
     23* `name` - Whether or not to require the user to provide a name with their email (true/false value). 
    2324 
    2425### Hooks 
     
    9192If a user visits the confirmation page without a valid confirmation URL, an error message will be displayed instead of the standard page contents. 
    9293 
     94## Email Address Validation 
     95 
     96Email address are validated using WordPress's `is_email()` function. It validates the general form of the email address, but cannot handle some international domain names. 
     97 
     98To use the more robust email validation provided by the MailGun API, use the filter `mailgun_subscriptions_validate_email_with_api`. Example: 
     99 
     100``` 
     101add_filter( 'mailgun_subscriptions_validate_email_with_api', '__return_true' ); 
     102``` 
     103 
     104Or you can use WordPress's `is_email` filter to apply your own validation. 
  • mailgun-subscriptions/trunk/readme.txt

    r1489834 r1703146  
    33Tags: mailing lists, subscriptions, widget, email 
    44Requires at least: 3.9 
    5 Tested up to: 4.6 
    6 Stable tag: 1.1.2 
     5Tested up to: 4.8 
     6Stable tag: 1.2.0 
    77License: GPL-2.0 
    88License URI: https://opensource.org/licenses/GPL-2.0 
     
    2020 
    2121== Changelog == 
     22 
     23= 1.2.0 = 
     24 
     25* Optional name field for the subscription widget (credit to Paul Ryley) 
     26* Fix PHP notice when first loading admin page 
     27* Default to WordPress email validation, with filter to use MailGun API 
    2228 
    2329= 1.1.2 = 
Note: See TracChangeset for help on using the changeset viewer.