latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

How has s2member replaced wp_user_query?

Home Forums Community Forum How has s2member replaced wp_user_query?

This topic contains 5 replies, has 3 voices. Last updated by  Lee Snow 3 years, 9 months ago.

Topic Author Topic
Posted: Thursday Mar 7th, 2013 at 2:49 pm #43985

So I am trying to use a bit of php code to add onto my website to search by first and last name in the WordPress back end.

The code works when s2member is disabled. It doesn’t when s2member is turned back on. From WordPress’s codex, I’m under the impression that the wp_user_query I’m using is referencing the wp_user and the wp_usermeta tables. What is s2member doing to not allow me to reference just this simple tables? I was trying to read through the s2member codex, and I noticed this: users_list_query, and tried to replace wp_user_query with it and also tried this one: c_ws_plugin__s2member_users_list. No dice.

Or maybe I’m way over my head on this. haha. Any help?

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Thursday Mar 7th, 2013 at 3:57 pm #43988

Or maybe I’m not even problem solving this right. Here is the code:

function user_search_by_multiple_parameters($wp_user_query) {
        if(false === strpos($wp_user_query->query_where, '@') && !empty($_GET["s"])) {

            global $wpdb;

            $uids=array();

            $usermeta_affected_ids = $wpdb->get_results("SELECT DISTINCT user_id FROM $wpdb->usermeta WHERE (meta_key='first_name' OR meta_key='last_name'".$iusib_add.") AND LOWER(meta_value) LIKE '%".$qstr."%'");

            foreach($usermeta_affected_ids as $maf) {
                array_push($uids,$maf->user_id);
            }

            $users_affected_ids = $wpdb->get_results("SELECT DISTINCT ID FROM $wpdb->users WHERE LOWER(user_nicename) LIKE '%".$qstr."%' OR LOWER(user_email) LIKE '%".$qstr."%'");

            foreach($users_affected_ids as $maf) {
                if(!in_array($maf->ID,$uids)) {
                    array_push($uids,$maf->ID);
                }
            }
			
            $id_string = implode(",",$uids);

            $wp_user_query->query_where = str_replace("user_nicename LIKE '%".$qstr."%'", "ID IN(".$id_string.")", $wp_user_query->query_where);
        }
        return $wp_user_query;
        
Posted: Saturday Mar 9th, 2013 at 10:05 am #44153

I don’t know if s2Member alters that… I’ll ask Jason about it.

I was trying to read through the s2member codex, and I noticed this: users_list_query, and tried to replace wp_user_query with it and also tried this one: c_ws_plugin__s2member_users_list. No dice.

[hilite mono]c_ws_plugin__s2member_users_list::users_list_query[/hilite] attaches to the hook [hilite mono]pre_user_query[/hilite] in the [hilite mono]WP_User_Query[/hilite] class. I don’t think you can use it separately because it expects a [hilite mono]WP_User_Query[/hilite] object by reference.

The code works when s2member is disabled. It doesn’t when s2member is turned back on.

Do you only have s2Member active or are there other plugins? If you have only s2Member active in the WP installation, do you still have that problem?

Posted: Thursday Mar 14th, 2013 at 2:21 pm #44636

I actually installed s2member on a clean testing environment with my theme installed. I then placed this script in, and it still doesn’t return the user by last name. But once I disable s2member, the script works.

So before that script enacts, I have

add_action('pre_user_query', 'user_search_by_multiple_parameters');

Should I then add an input to the action like below or make a separate action?

add_action('pre_user_query', 'user_search_by_multiple_parameters', 'c_ws_plugin__s2member_users_list');

Thanks again for any help you can pass my way.

Posted: Friday Mar 15th, 2013 at 10:06 am #44700
Staff Member

Thanks for the heads up on this thread :-)

I think that would be a good idea for s2Member® to include the first/last names by default. Currently, it searches only the Display Name field. We’re going to have this updated in the next maintenance release.

Until then, I’m attaching a PATCH file for you. If you’d like to patch your existing installation, please download and unzip the attached file. Please upload the file to your installation, allowing it to override your existing copy of: /s2member/includes/classes/users-list.inc.php

http://d1v41qemfjie0l.cloudfront.net/s2member/uploads/users-list.inc_.php_.zip

If you look at s2Member’s source code in this file, you will find that it exposes several additional WP filters that would allow you to customize user searches even further. Please see class method users_list_query in this file.

Posted: Friday Mar 15th, 2013 at 10:52 am #44709

Fantastic! Thank you! It works!

I’m also running some heavy plugins, which are Event Espresso, Easy Reservation, CIMY (which is about to go away, still need to port the data), BuddyPress, and W3 Total Cache, and seem to not conflict at all with the search.

Viewing 5 replies - 1 through 5 (of 5 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.