[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-content/add-ons/ -> MailPress_mailinglist_US_state.php (source)

   1  <?php
   2  if (class_exists('MailPress') && !class_exists('MailPress_mailinglist_US_state') )
   3  {
   4  /*
   5  Plugin Name: MailPress_mailinglist_US_state
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/mailinglist_us_state/
   7  Description: New Mail : Mailing lists : based on US State (<span style='color:red;'>beware !</span> IP geolocation search is not 100% accurate)
   8  Version: 5.4.4
   9  */
  10  
  11  class MailPress_mailinglist_US_state
  12  {
  13  	function __construct()
  14      {
  15  // for sending mails
  16          add_filter('MailPress_mailinglists_optgroup',     array(__CLASS__, 'mailinglists_optgroup'), 12, 2);
  17          add_filter('MailPress_mailinglists',             array(__CLASS__, 'mailinglists'), 12, 1);
  18          add_filter('MailPress_query_mailinglist',         array(__CLASS__, 'query_mailinglist'), 12, 2);
  19      }
  20  
  21  //// Sending Mails ////
  22  
  23  	public static function mailinglists_optgroup( $label, $optgroup ) 
  24      {
  25          if (__CLASS__ == $optgroup) return __('US State codes', MP_TXTDOM);
  26          return $label;
  27      }
  28  
  29  	public static function mailinglists( $draft_dest = array() ) 
  30      {
  31          global $wpdb;
  32  
  33          $rows = $wpdb->get_results( "SELECT DISTINCT created_US_State as US_State FROM $wpdb->mp_users WHERE created_country = 'US' AND status = 'active' ORDER BY 1" );
  34  
  35          foreach ($rows as $row) $draft_dest[__CLASS__ . '~' . $row->US_State] = $row->US_State;
  36  
  37          return $draft_dest;
  38      }
  39  
  40  	public static function query_mailinglist( $query, $draft_toemail ) 
  41      {
  42          if ($query) return $query;
  43  
  44          $US_State = str_replace(__CLASS__ . '~', '', $draft_toemail, $count);
  45          if (0 == $count) return $query;
  46          if (empty($US_State))  return $query;
  47  
  48          global $wpdb;
  49          return "SELECT DISTINCT c.id, c.email, c.name, c.status, c.confkey FROM $wpdb->mp_users c WHERE c.created_country = 'US' AND c.created_US_State = '$US_State' AND c.status = 'active' ";
  50      }
  51  }
  52  new MailPress_mailinglist_US_state();
  53  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1