Email Users Custom Lists

A recent question on the WordPress Support forum got me thinking on how to solve this user’s question.  The obvious answer was to use the Custom Meta filter capability which has been part of Email Users for quite a while.

The one limitation of Custom Meta filters was the limitation in how WordPress support SQL wildcards in the LIKE and NOT LIKE constructs.  WordPress would add unwanted escape characters preventing the wildcard from matching rendering LIKE and NOT LIKE largely useless.  I had submitted a WordPress patch 4+ years ago when I ran into this issue and expected it to be fixed in WordPress 3.6.  It was never incorporated, I am not sure why, there isn’t much of an explanation in the ticket.

When I started looking back into this today I found that WordPress had added support for regular expressions (REGEXP, NOT REGEXP) to user meta queries.  This is good news as it is actually a better, and easier to use, solution than using the SQL LIKE construct.

I have updated Email Users to reflect this recommended usage, all of the examples have switched from LIKE to REGEXP and I’ve added a couple more.  I’ve also updated the example plugin I use to test these custom meta queries.  I prefer to put these type of things in a small plugin instead of the theme’s functions.php file because risk of losing them with a theme update or change is much lower.

Email Users Custom List (247 downloads)

 

Example:  Select Users with Last Name beginning with M:

add_action( 'mailusers_user_custom_meta_filter', 'last_names_starting_with_m', 5 );

function last_names_starting_with_m()
{
 mailusers_register_user_custom_meta_filter('Last Name: M', 'last_name', '^M', 'REGEXP');
}

Example:  Select Users with Last Names beginning with S-Z:

</pre>
add_action( 'mailusers_user_custom_meta_filter', 'last_names_starting_with_s_through_z', 5 );

function last_names_starting_with_s_through_z()
{
mailusers_register_user_custom_meta_filter('Last Name: S-Z', 'last_name', '^[S-Z]', 'REGEXP');
}
<pre>