Community Support Forums — WordPress® ( Users Helping Users ) — 2011-05-19T00:41:47-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=6475 2011-05-19T00:41:47-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15356#p15356 <![CDATA[Re: Hook/Filter to add field to User List Search]]> Statistics: Posted by toddz88 — May 19th, 2011, 12:41 am


]]>
2011-05-18T17:07:07-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15321#p15321 <![CDATA[Re: Hook/Filter to add field to User List Search]]> arrays before saving / retrieving from the DB (found that out by accident).

also if you don't add

Code:
AND meta_key = 'wp__s2member_custom_fields'


to limit the scope of the db search, it will end searching every record in the user meta table
which will slow down your search.

Pete..

Statistics: Posted by peterhuk — May 18th, 2011, 5:07 pm


]]>
2011-05-18T16:11:45-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15313#p15313 <![CDATA[Re: Hook/Filter to add field to User List Search]]> I didn't realize that s2m stores its CustRegFields as a serialized STRING.. which IS searchable with a " LIKE '%%var%%' " query. I thought it was actually an array in there, since i was looking at my print_r output and seeing it as a structured array. But yes, now i also see instances in the print_r of the serialized string with the same data. So here's what I ended up doing, which works perfectly for me:

Code:
# PREP VARS
// vars for the Query
$group_name = ""; //get from the GroupManager's data, from s2m api Notification.
$group_name_chars = strlen($group_name);
// vars to update in each user (member) of the Group // also get from GroupMaster's data
$group_eot = '';
$group_cancel_date = '';

# FIND USERS IN THE GROUP
$tz_query = sprintf("SELECT * FROM $wpdb->usermeta WHERE meta_value LIKE '%%;s:10:\"group_acct\";s:%d:\"%s\";%%' ",$group_name_chars,$group_name);
$tz_results = $wpdb->get_results($tz_query,OBJECT); // result is an array of objects.

# UPDATE USERS IN THE GROUP
foreach ($tz_results as $group_member){
   //echo $group_member->user_id; //test
   
   # get
   $user_id = $group_member->user_id;
   $option_name = 's2member_custom_fields'; //set var
   $s2m_custom_fields = get_user_option($option_name, $user_id); //get array
   
   # set
   $s2m_custom_fields['eot'] = $group_eot;
   $s2m_custom_fields['cancel_date'] = $group_cancel_date;
   $newvalue = $s2m_custom_fields;
   $s2m_custom_fields_update = update_user_option( $user_id, $option_name, $newvalue );
   
}


Thanks again peterhuk.. you lead me in exactly the right direction.

Statistics: Posted by toddz88 — May 18th, 2011, 4:11 pm


]]>
2011-05-18T14:32:02-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15306#p15306 <![CDATA[Re: Hook/Filter to add field to User List Search]]>
you can easily create your own search function and if you know all the groups you are likely to create the
you can add all the combinations into an array (inc serialised info) i.e

$groups = array(
'twitter' => '%s:5:"group";s:7:"Twitter"%'
'facebook' => '%s:5:"group";s:8:"facebook"%'
)

then the searches can be referenced via the array

Pete..

Statistics: Posted by peterhuk — May 18th, 2011, 2:32 pm


]]>
2011-05-18T14:26:12-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15304#p15304 <![CDATA[Re: Hook/Filter to add field to User List Search]]>
re:


So $wpdb was already invoked by the code i hooked into. Unless .. as I said in my original post .. i'm just not doing it correctly.


Your function does not have an input field and therefore $wpdb will be returned as undefined
(check your error logs).

Second WP stores meta data in serialized form so therefor the only otherway I can suggest
is to do a full text seach of the meta_value colum for something like
Code:
s:XX:"yourgroup";s:YY:"name"


Where XX being the number of chars in yourgroup (9)
and YY being the number of chars in name (5)

i.e
Code:
SELECT * FROM wp_usermeta WHERE meta_key = 'wp__s2member_custom_fields'
AND meta_value LIKE '%s:5:"group";s:7:"Twitter"%'

you'll need to do an inner join to include the wp_users table
Hope this helps

Pete..

Statistics: Posted by peterhuk — May 18th, 2011, 2:26 pm


]]>
2011-05-18T13:47:37-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15300#p15300 <![CDATA[Re: Hook/Filter to add field to User List Search]]> First, thank you very much.. i really do appreciate the help and attention you're offering.


..then during the registration process..

My "group" value won't be known/determined at the time of registration; it will be set later by the site administrator, and added to the user's profile manually, via wp-admin>users.


..search for the relevent group in a non S2m environment..

s2m stores ALL of its custom-reg-fields in an array, in a single user-meta field called "myTablePrefix_s2member_custom_fields". And the standard wordpress method to SEARCH user meta-data -- get_users() or the WP_User_Query class -- don't seem to be able to reach my Group value since it's nested in that array. So by using my own custom user-meta field, I can have the Group value be a simple string that get_users() could use. Or perhaps there's a way to customize WP_User_Query for that, but it didn't seem easy/obvious to me.


..includes the $wpdb class but you have not invoked the global class..

My function is (trying to) just insert the contents of $my_search" (which yes, uses $wpdb) into s2m's Search Form modification code (line 74 of s2member/includes/classes/users-list.inc.php), using a Hook explicity for the purpose of adding more custom fields to the search query. So $wpdb was already invoked by the code i hooked into. Unless .. as I said in my original post .. i'm just not doing it correctly.

So really, I'm looking for EITHER:

A) help with the Hook/Filter "ws_plugin__s2member_before_users_list_search_where_or_after" (line 74 of s2member/includes/classes/users-list.inc.php). ..(or)..

B) help getting get_users() or WP_User_Query to search for a string (like "Acme") in the Value of an array element who's Key is "Group", all inside an array which is in a user-meta field called "wp_kjk_s2member_custom_fields". (I probably made that sound more complicated than it hopefully is).

Hmm, maybe i'll post a new topic/question for (B), since that's a totally different approach.

Statistics: Posted by toddz88 — May 18th, 2011, 1:47 pm


]]>
2011-05-18T13:07:03-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15295#p15295 <![CDATA[Re: Hook/Filter to add field to User List Search]]>
Code:
function my_other_field(){
   $my_search = " OR (`" . $wpdb->usermeta . "`.`meta_key` = '" . $wpdb->prefix . "twitter' AND `" . $wpdb->usermeta . "`.`meta_value` LIKE '" . $s . "')";
   return $my_search;
}


includes the $wpdb class but you have not invoked the global class
i.e
Code:
global $wpdb;


prior to calling the class.

hope that helps

Pete..

Statistics: Posted by peterhuk — May 18th, 2011, 1:07 pm


]]>
2011-05-18T12:57:22-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15294#p15294 <![CDATA[Re: Hook/Filter to add field to User List Search]]>
I would probably still recomend using the

s2Member General Options -> Custom Registration Fields

then during the registration process (you will need to find the appropriate hook)
add a seperate user meta for the group you require.

This will allow you to use S2M via the user admin console to do searches and also
using your group user meta that was defined previously search for the relevent
group in a non S2m environment.

Hope this helps

Pete..

Statistics: Posted by peterhuk — May 18th, 2011, 12:57 pm


]]>
2011-05-18T10:23:49-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15279#p15279 <![CDATA[Re: Hook/Filter to add field to User List Search]]>
The reason I am trying to NOT use an s2m Custom Registration Field is that those are stored in a an ARRAY WITHIN a custom user field, which makes the value much harder to access when using a wordpress function to Search / Query / Find users, based on that value.

Ultimately i need to find all Users where "Group" = "Acme", and update them all, setting their "EOT" to a certain value.

The function WP_User_Query works, but not for s2m custom-reg-fields:
Code:
$wp_user_search = new WP_User_Query( array(
   'role' => 'subscriber'
) );
$my_group = $wp_user_search->get_results();


And wp's get_users() also works, but again not for s2m custom-reg-fields:
Code:
$args = array(
   'meta_key' => 'aim',
   'meta_value' => 'Bertha',
   'meta_compare' => '='
);
$my_group = get_users( $args );

And this one also works with a meta_key of "twitter" (which would eventually be "group" for me). That's why I was trying to use a NON s2m custom-reg-field.

But the problem becomes that my custom field (whether 'twitter' or 'group') is not SEARCHABLE on the WP-Admin > Users screen, and I can't use my own hooks there, since s2m is already doing that, so i need to hook into s2m's modification of the search form on that page.

Hope this clarifies the larger situation. And thanks again for any insights.
-Todd

Statistics: Posted by toddz88 — May 18th, 2011, 10:23 am


]]>
2011-05-18T06:12:58-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15273#p15273 <![CDATA[Re: Hook/Filter to add field to User List Search]]>
Why not try adding a Twitter Custom Registration Fields:

s2Member General Options -> Custom Registration Fields

This will provide a Twitter input field for your users to complete
at registration and allow existing user to add / update their
Twitter info.

You'll probably save yourself a lot of time :D

Pete..

Statistics: Posted by peterhuk — May 18th, 2011, 6:12 am


]]>
2011-05-18T02:56:04-05:00 http://www.primothemes.com/forums/viewtopic.php?t=6475&p=15262#p15262 <![CDATA[Hook/Filter to add field to User List Search]]>
But I have a custom user-profile field that is NOT part of s2m, called "twitter". I am able to display a column for it, and populate it with data correctly. But unlike the s2m fields, this one is NOT (yet) searchable.

I found some nice HOOKS in s2member/includes/classes/users-list.inc.php (lines 66-80), that seem intended to allow us to add additional fields to the User Search functionality. Especially line 74:
Code:
$query->query_where .= apply_filters ("ws_plugin__s2member_before_users_list_search_where_or_after", "", get_defined_vars ()) . ")"; /* Leaving room for additional searches here. */


I took a stab at a function for this hook, in my s2-hacks.php:
Code:
add_filter ("ws_plugin__s2member_before_users_list_search_where_or_after", "my_other_field");
function my_other_field(){
   $my_search = " OR (`" . $wpdb->usermeta . "`.`meta_key` = '" . $wpdb->prefix . "twitter' AND `" . $wpdb->usermeta . "`.`meta_value` LIKE '" . $s . "')";
   return $my_search;
}


The query part is based on the other queries in users-list.inc.php, just changing the field name from "s2member_custom" to my "twitter".
Code:
$query->query_where .= " OR (`" . $wpdb->usermeta . "`.`meta_key` = '" . $wpdb->prefix . "s2member_custom' AND `" . $wpdb->usermeta . "`.`meta_value` LIKE '" . $s . "')";


But it's not working. Can anyone say if I'm using the Hook as intended; if my Filter makes sense; or offer any insight about why it's not working?

Thanks!
todd

Statistics: Posted by toddz88 — May 18th, 2011, 2:56 am


]]>