Hook/Filter to add field to User List Search
Posted: May 18th, 2011, 2:56 am
s2member's custom registration fields are nicely added as columns to the WP-Admin > Users list. And even better.. they are actually SEARCHABLE in the Search Users box (top right of the page).
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:
I took a stab at a function for this hook, in my s2-hacks.php:
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".
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
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: Select all
$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: Select all
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: Select all
$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