Plugin Directory

Changeset 1893633


Ignore:
Timestamp:
06/15/2018 04:45:17 PM (8 years ago)
Author:
emfluencekc
Message:

Plugin v2.3: Add email domain blacklist setting

Location:
wp-emfluence/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-emfluence/trunk/admin.php

    r1421095 r1893633  
    3232      ,'account'
    3333  );
     34  add_settings_field(
     35      'blacklist_domains',
     36      'Blacklist Domains',
     37      '_emfluence_emailer_options_blacklist_domains_element',
     38      'emfluence_emailer',
     39      'account'
     40  );
    3441}
    3542add_action('admin_init', 'emfluence_emailer_admin_init');
     
    4148    return;
    4249  }
    43  
     50
    4451  wp_enqueue_style(
    4552      'emfluence-widget',
     
    4754      array(),
    4855      filemtime(__DIR__ . '/css/widget-settings.css')
    49     );
     56  );
    5057
    5158  wp_enqueue_script(
     
    6471 */
    6572function _emfluence_emailer_options_page() {
    66 ?>
    67 <div class="emfluence wrap">
    68     <h2><?php __( 'emfluence Marketing Platform' ); ?></h2>
     73  ?>
     74  <div class="emfluence wrap">
     75    <h2><?php __( 'emfluence Marketing Platform' ); ?></h2>
    6976
    70   <form action="options.php" method="post">
    71     <?php settings_fields('emfluence_emailer'); ?>
    72     <?php do_settings_sections('emfluence_emailer'); ?>
     77    <form action="options.php" method="post">
     78      <?php settings_fields('emfluence_emailer'); ?>
     79      <?php do_settings_sections('emfluence_emailer'); ?>
    7380
    74     <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
    75   </form>
     81      <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
     82    </form>
    7683
    77 </div>
    78 <?php
     84  </div>
     85  <?php
    7986}
    8087
     
    8895}
    8996
     97function _emfluence_emailer_options_blacklist_domains_element(){
     98  $options = get_option('emfluence_global');
     99  if(!array_key_exists('blacklist_domains', $options)) $options['blacklist_domains'] = '';
     100  echo "
     101    <textarea id='blacklist_domains' name='emfluence_global[blacklist_domains]' rows='10'>{$options['blacklist_domains']}</textarea>
     102    <p>Form submissions with email address recipients in these domains will be rejected.</p>
     103    <p>This is useful if you only want B2B leads.</p>
     104    <p>Enter one domain per line, without commas. For example:<br />
     105      hotmail.com<br />
     106      gmail.com<br />
     107      aol.com
     108    </p>
     109    ";
     110}
     111
    90112/**
    91113 * Validates posted settings page options
     
    94116 */
    95117function _emfluence_emailer_options_validate($data){
     118  if(empty($data['api_key'])) return $data;
     119
    96120  // Create a new instance of the api
    97121  $api = emfluence_get_api($data['api_key'], TRUE);
  • wp-emfluence/trunk/emfluence.php

    r1636887 r1893633  
    55Description: Easily add forms to your website for contacts to add or update their details in your emfluence Marketing Platform account.
    66Author: emfluence Digital Marketing
    7 Version: 2.2
     7Version: 2.3
    88Author URI: https://www.emfluence.com
    99*/
  • wp-emfluence/trunk/readme.txt

    r1673829 r1893633  
    11=== Plugin Name ===
    22Tags: email, email marketing, emailmarketing, emfluence, api, marketing automation, widget, email widget, email signup, mailing list, newsletter, form, automation
    3 Requires at least: 3.0.1
    4 Tested up to: 4.8
    5 Stable tag: 2.2
     3Requires at least: 4.0
     4Tested up to: 4.9.6
     5Stable tag: 2.3
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5252== Changelog ==
    5353
     54= 2.3 =
     55* Add blacklist domain setting on plugin admin page.
     56* Fix warning if there is any non-string POST data on form submit.
     57* Scroll to location of form on page after form submit.
     58
     59= 2.2.1 =
     60* Fail more gracefully in the admin area if API token is not available.
     61
    5462= 2.2 =
    5563* Add honeypot to cut down on spam submissions.
  • wp-emfluence/trunk/widget.php

    r1636887 r1893633  
    6363   */
    6464  protected function validate_email($email) {
     65
    6566    // Ensure the basic pattern is correct
    6667    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    6768      return false;
    68     } else {
    69       // Test the domain's MX records to avoid more fake domains in the correct pattern.
    70       list($user, $domain) = explode('@', $email);
    71       try {
    72         if( !checkdnsrr($domain, 'MX') ){
    73           return false;
    74         }
    75       } catch( Exception $e ){
     69    }
     70
     71    // Test the domain's MX records to avoid more fake domains in the correct pattern.
     72    list($user, $domain) = explode('@', $email);
     73    try {
     74      if( !checkdnsrr($domain, 'MX') ){
    7675        return false;
    7776      }
    78     }
     77    } catch( Exception $e ){
     78      return false;
     79    }
     80
     81    // Check domain blacklist
     82    $options = get_option('emfluence_global');
     83    if(!empty($options['blacklist_domains'])) {
     84      $blacklisted_domains = array_map(
     85          function ($domain) { return strtolower(trim($domain)); },
     86          array_filter(explode(PHP_EOL, $options['blacklist_domains']))
     87      );
     88      if(in_array(strtolower($domain), $blacklisted_domains, true)) return false;
     89    }
     90
    7991    return true;
    8092  }
     
    124136        case 'email':
    125137          if(!$this->validate_email( $values[$key] )) {
    126             $messages[] = array( 'type' => 'error', 'value' => sprintf(__('%s: Invalid email address.'), $field_name) );
     138            $messages[] = array( 'type' => 'error', 'value' => sprintf(__('%s: Invalid email address or blacklisted email domain.'), $field_name) );
    127139          }
    128         break;
     140          break;
    129141        case 'number':
    130142          if(!is_numeric($values[$key])) {
     
    153165    if( $title ) $title = $args['before_title'] . '<span>' . $title . '</span>' . $args['after_title'];
    154166
    155     $output = $args['before_widget'] . '<form class="mail-form" method="post"><div class="holder"><div class="frame">';
     167    $output = $args['before_widget'] . '<form id="' . esc_attr($args['widget_id']) . '" class="mail-form" method="post" action="#' . esc_attr($args['widget_id']) . '"><div class="holder"><div class="frame">';
    156168    $output .= $title;
    157169    $output .= $content;
     
    189201      // Set the field values in case there's an error
    190202      foreach( $_POST as $key => $value ){
     203        if(!is_string($value)) continue;
    191204        $values[$key] = htmlentities( trim( $value ) );
    192205      }
     
    220233          }
    221234          $data['customFields'][$field] = array(
    222             'value' => trim( $_POST[$parameter] ),
     235              'value' => trim( $_POST[$parameter] ),
    223236          );
    224237        }
     
    343356        array(),
    344357        filemtime(__DIR__ . '/css/widget-frontend.css')
    345       );
     358    );
    346359    return;
    347360  }
     
    376389        'New email signup form submission for "' . $instance['title'] . '"',
    377390        $message
    378         );
     391    );
    379392  }
    380393
     
    428441        </div>
    429442        <div class="selected">' . "\n";
    430         if( !empty($instance['groups']) ) {
    431           foreach ($instance['groups'] as $groupID) {
    432             $group = $groups[$groupID];
    433             $id = 'groups-' . $this->number . '-' . $groupID;
    434             $output .= '
     443    if( !empty($instance['groups']) ) {
     444      foreach ($instance['groups'] as $groupID) {
     445        $group = $groups[$groupID];
     446        $id = 'groups-' . $this->number . '-' . $groupID;
     447        $output .= '
    435448              <div>
    436449                <label for="' . $id . '">
     
    438451                </label>
    439452              </div>';
    440           }
    441         }
     453      }
     454    }
    442455    $output .= '
    443456        </div>
     
    867880  public function form( $instance ) {
    868881    $options = get_option('emfluence_global');
     882    if(empty($options['api_key'])) {
     883      print '<div class="wp-emfluence">Please visit the emfluence plugin settings page and add an API token.</div>';
     884      return;
     885    }
    869886    $api = emfluence_get_api($options['api_key']);
    870887    $ping = $api->ping();
     
    936953      $is_custom_display = (
    937954          strrpos($field_key, '_display') === (strlen($field_key) - strlen('_display'))
    938           );
     955      );
    939956      if(!$is_custom_display) continue;
    940957
     
    961978          'order' => is_numeric($new_instance[$key_prefix . '_order'])? $new_instance[$key_prefix . '_order'] : 6,
    962979          'type' => empty($instance[$key_prefix . '_type']) ? 'text' : $this->restrict_to_types($instance[$key_prefix . '_type'])
    963         );
     980      );
    964981    }
    965982
Note: See TracChangeset for help on using the changeset viewer.