Email-Users 4.4.1-beta-2 available

I have uploaded v4.4.1. beta-2 for Email Users.  This version changes the custom filters previously defined to be a “user” filter and introduces a “group” filter.  If you have used the “Send to Group” feature, you can now define a series of filters that you can send to.   There are examples of sending to the “Police” and “Fire” departments in the example filter plugin (see below).

EU_SS_06

I have updated the example plugin to create the filters, you download it and drop it into  your plugins directory to see menus like shown in the beta-1 post.

There is also a new option on the plugin settings page to control where bounced emails are sent.

Email Users Custom List (452)

Please download and test the beta release.  Report back any issues and I’ll do what I can to fix them quickly.

Email Users Beta (112)

3 thoughts on “Email-Users 4.4.1-beta-2 available

  1. Mike, if you write the function for a custom user group so that it takes only 2 parameters ($label and $meta_filter) then using the code in https://gist.github.com/4137084 you can pass the $meta_filter and have an array of $meta_values returned. If you pass both $meta_value and $meta_filter you will get an array of email addresses returned.

    What I had envisioned was passing only a label and the $meta_value then having a list returned to choose from. Something like ‘Label – $meta_value[i]‘. The selection of this would then pass both $meta_filter and $meta_value to the function which would then return an array of email addresses for Email Users.

    In this use case, there doesn’t need to be sorting or selecting of certain values from within the group.

    If you write the function to accept these arrays as input I think you could just add the other code and have it working. I’ll look to change the gist code to return a key/value pair to use the name or slug.

    • Sorry for the delayed response on this, it was a busy weekend of basketball (four games) and soccer (two games). I took a look at your Gist and it is possible to implement what you want to do with what I have already implemented. Take a look at this code, I think it does what you want although you might want to tweak the logic for the label a bit:


      /**
      * Build a Custom Meta Group Filter based on a meta field.
      * This class will find all possible values for a specific
      * meta field and then add the appropriate action for each
      * one it finds.
      *
      */
      class CustomMetaGroupFilter
      {
      /**
      * Retrieve all of the users who have a specific
      * meta field attached with an optionally supplied
      * value.
      *
      * @param $meta_key string name of the user meta key
      * @param $meta_value string optional value of the user meta key
      */
      private function get_users_by_meta_key($meta_key, $meta_value = null)
      {
      // Query for users based on the meta data

      $uq = new WP_User_Query(array('meta_key' => $meta_key, 'meta_value' => $meta_value )) ;

      return $uq->get_results() ;
      }

      /**
      * Retrieve all of the possible values for a user meta field.
      * meta field attached with an optionally supplied
      * value.
      *
      * @param $meta_key string name of the user meta key
      * @param $meta_value string optional value of the user meta key
      */
      private function get_user_meta_key_values($meta_key, $meta_value = null)
      {
      $meta_values = array() ;

      foreach (self::get_users_by_meta_key($meta_key, $meta_value) as $user)
      $meta_values = array_merge($meta_values, (array)get_user_meta($user->ID, $meta_key, $meta_value)) ;

      sort($meta_values) ;

      return array_unique($meta_values) ;
      }

      /**
      * Retrieve all of the possible values for a user meta field.
      * meta field attached with an optionally supplied
      * value.
      *
      * @param $meta_key string name of the user meta key
      * @param $meta_value string optional value of the user meta key
      */
      public function BuildFilter($meta_key, $meta_value = null)
      {
      $meta_values = self::get_user_meta_key_values($meta_key, $meta_value) ;

      // Loop through meta values and add an action for each one

      foreach ($meta_values as $mv)
      {
      $fn = create_function('',
      sprintf('mailusers_register_group_custom_meta_filter(\'%s\', \'%s\', \'%s\');',
      ucwords($mv . ' ' . $meta_key), $meta_key, $mv)) ;
      add_action('mailusers_group_custom_meta_filter', $fn) ;
      }
      }
      }

      CustomMetaGroupFilter::BuildFilter('department') ;

      This class (which could go in a theme’s functions.php or as a stand-alone plugin) will find all of the values for a meta key and add the action required for the group meta filter for each one. I am unsure whether something like this should be part of the plugin or not because it makes the decision for the label filter which is something people may want to do themselves. I suppose I could provide it as part of the plugin and if someone wanted more customization they could extend the class.

    • Take a look at this post and see if this is closer to what you were looking for.

Leave a Reply