Changeset 1703146
- Timestamp:
- 07/26/2017 01:59:08 PM (9 years ago)
- Location:
- mailgun-subscriptions/trunk
- Files:
-
- 14 edited
-
Mailgun_Subscriptions/Account_Management_Subscription_Request_Handler.php (modified) (2 diffs)
-
Mailgun_Subscriptions/Account_Management_Token_Request_Handler.php (modified) (1 diff)
-
Mailgun_Subscriptions/Admin_Page.php (modified) (1 diff)
-
Mailgun_Subscriptions/Confirmation.php (modified) (5 diffs)
-
Mailgun_Subscriptions/Confirmation_Handler.php (modified) (2 diffs)
-
Mailgun_Subscriptions/Null_Confirmation.php (modified) (1 diff)
-
Mailgun_Subscriptions/Plugin.php (modified) (1 diff)
-
Mailgun_Subscriptions/Shortcode_Handler.php (modified) (2 diffs)
-
Mailgun_Subscriptions/Submission_Handler.php (modified) (3 diffs)
-
Mailgun_Subscriptions/Subscription_Form.php (modified) (3 diffs)
-
Mailgun_Subscriptions/Widget.php (modified) (3 diffs)
-
mailgun-subscriptions.php (modified) (1 diff)
-
readme.md (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Account_Management_Subscription_Request_Handler.php
r1469692 r1703146 24 24 switch ( $this->action ) { 25 25 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' ] ); 27 27 break; 28 28 case 'account-unsubscribe': … … 39 39 } 40 40 41 private function handle_subscribe_request( $email_address, $list_address ) {41 private function handle_subscribe_request( $email_address, $list_address, $name = '' ) { 42 42 $submission_handler = new Submission_Handler( array( 43 43 'mailgun-lists' => array( $list_address ), 44 44 'mailgun-subscriber-email' => $email_address, 45 'mailgun-subscriber-name' => $name, 45 46 )); 46 47 $submission_handler->handle_request(); -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Account_Management_Token_Request_Handler.php
r1469692 r1703146 43 43 44 44 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; 47 51 } 48 52 -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Admin_Page.php
r1489834 r1703146 343 343 $lists = $this->get_mailing_lists_from_cache(); 344 344 $addresses = wp_list_pluck( $lists, 'address' ); 345 $saved = get_option('mailgun_lists');345 $saved = (array) get_option('mailgun_lists'); 346 346 $gone = array_diff( array_keys($saved), $addresses ); 347 347 if ( !empty($gone) ) { -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Confirmation.php
r994371 r1703146 11 11 protected $post_id = ''; 12 12 protected $address = ''; 13 protected $name = ''; 13 14 protected $confirmed = FALSE; 14 15 protected $lists = array(); … … 43 44 } 44 45 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 } 45 59 46 60 public function save() { … … 51 65 'post_status' => 'publish', 52 66 '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 ), 54 68 'post_name' => $this->id, 55 69 )); … … 57 71 delete_post_meta( $this->post_id, '_mailgun_subscriber_lists' ); 58 72 update_post_meta( $this->post_id, '_mailgun_subscriber_address', $this->address ); 73 update_post_meta( $this->post_id, '_mailgun_subscriber_name', $this->name ); 59 74 update_post_meta( $this->post_id, '_mailgun_subscription_confirmed', $this->confirmed ); 60 75 foreach ( $this->lists as $list ) { … … 82 97 $this->post_id = reset($results); 83 98 $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); 84 100 $this->lists = get_post_meta($this->post_id, '_mailgun_subscriber_lists', false); 85 101 $this->confirmed = get_post_meta($this->post_id, '_mailgun_subscription_confirmed', true); -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Confirmation_Handler.php
r1469692 r1703146 70 70 protected function do_subscription() { 71 71 $address = $this->confirmation->get_address(); 72 $name = $this->confirmation->get_name(); 72 73 $lists = $this->confirmation->get_lists(); 73 74 $api = Plugin::instance()->api(); … … 75 76 $response = $api->post("lists/$list_address/members", array( 76 77 'address' => $address, 78 'name' => $name, 77 79 'upsert' => 'yes', 78 80 )); -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Null_Confirmation.php
r994371 r1703146 15 15 16 16 public function get_address() { 17 return ''; 18 } 19 20 public function set_name( $name ) { 21 // do nothing 22 } 23 24 public function get_name() { 17 25 return ''; 18 26 } -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Plugin.php
r1489834 r1703146 6 6 7 7 class Plugin { 8 const VERSION = '1. 1.2';8 const VERSION = '1.2.0'; 9 9 10 10 /** @var Plugin */ -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Shortcode_Handler.php
r1469692 r1703146 65 65 'description' => '', 66 66 'lists' => '', 67 'name' => false, 67 68 ), $atts); 68 69 if ( empty($atts['lists']) ) { … … 77 78 'description' => $atts['description'], 78 79 'lists' => $lists, 80 'name' => wp_validate_boolean($atts['name']), 79 81 )); 80 82 return ob_get_clean(); -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Submission_Handler.php
r1469692 r1703146 60 60 61 61 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 } 63 67 if ( !$valid ) { 64 68 $this->error_details['invalid-email'][] = $address; … … 92 96 $confirmation = new Confirmation(); 93 97 $confirmation->set_address($this->get_submitted_address()); 98 $confirmation->set_name($this->get_submitted_name()); 94 99 $confirmation->set_lists($this->get_submitted_lists()); 95 100 $confirmation->save(); … … 100 105 $address = isset($this->submission['mailgun-subscriber-email']) ? $this->submission['mailgun-subscriber-email'] : ''; 101 106 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; 102 112 } 103 113 -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Subscription_Form.php
r1469692 r1703146 117 117 echo '</p>'; 118 118 } 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 119 126 echo '<p class="email-address">'; 120 127 printf( '<label for="mailgun-email-address-%d">%s</label> ', $instance_counter, __('Email Address', 'mailgun-subscriptions') ); … … 124 131 $default_email = $user->user_email; 125 132 } 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') ); 127 134 echo '</p>'; 128 135 printf( '<p class="submit"><input type="submit" value="%s" /></p>', apply_filters( 'mailgun_subscription_form_button_label', __('Subscribe', 'mailgun-subscriptions') ) ); … … 169 176 return $url; 170 177 } 171 } 178 } -
mailgun-subscriptions/trunk/Mailgun_Subscriptions/Widget.php
r1469692 r1703146 37 37 'description' => $content, 38 38 'lists' => $instance['lists'], 39 'name' => isset($instance['name']), 39 40 )); 40 41 … … 51 52 52 53 public function update( $new_instance, $old_instance ) { 53 $instance = $ old_instance;54 $instance = $new_instance; 54 55 $instance['title'] = strip_tags($new_instance['title']); 55 $instance['content'] = $new_instance['content'];56 $instance['lists'] = $new_instance['lists'];57 56 return $instance; 58 57 } … … 82 81 <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> 83 82 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> 85 89 <ul> 86 90 <?php foreach ( Plugin::instance()->get_lists('name') as $list_address => $list_settings ): ?> -
mailgun-subscriptions/trunk/mailgun-subscriptions.php
r1489834 r1703146 6 6 Author: Flightless 7 7 Author URI: http://flightless.us/ 8 Version: 1. 1.28 Version: 1.2.0 9 9 Text Domain: mailgun-subscriptions 10 10 Domain Path: /languages -
mailgun-subscriptions/trunk/readme.md
r1469692 r1703146 13 13 ## Subscription Form Widget 14 14 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.15 The 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. 16 16 17 17 ## Shortcode … … 21 21 * `lists` - The email addresses of the lists that should be available in the form. 22 22 * `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). 23 24 24 25 ### Hooks … … 91 92 If a user visits the confirmation page without a valid confirmation URL, an error message will be displayed instead of the standard page contents. 92 93 94 ## Email Address Validation 95 96 Email 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 98 To use the more robust email validation provided by the MailGun API, use the filter `mailgun_subscriptions_validate_email_with_api`. Example: 99 100 ``` 101 add_filter( 'mailgun_subscriptions_validate_email_with_api', '__return_true' ); 102 ``` 103 104 Or you can use WordPress's `is_email` filter to apply your own validation. -
mailgun-subscriptions/trunk/readme.txt
r1489834 r1703146 3 3 Tags: mailing lists, subscriptions, widget, email 4 4 Requires at least: 3.9 5 Tested up to: 4. 66 Stable tag: 1. 1.25 Tested up to: 4.8 6 Stable tag: 1.2.0 7 7 License: GPL-2.0 8 8 License URI: https://opensource.org/licenses/GPL-2.0 … … 20 20 21 21 == 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 22 28 23 29 = 1.1.2 =
Note: See TracChangeset
for help on using the changeset viewer.