Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

How to search Q2A users by email or username as an admin

+7 votes
179 views
asked Apr 4, 2017 in Q2A Core by htabar
Hi There,

As an admin, how I can search for a user by their email or username?

Thanks
Q2A version: 1.7.4
commented Apr 4, 2017 by Gurjyot Singh
It would have been a nice feature but, Q2A doesn't have this feature as off now.

1 Answer

+1 vote
answered Apr 5, 2017 by bluegenel
commented Apr 11, 2017 by htabar
Thank you. This plugin searches for usernames. Do you know how we can search for users by email? thanks
commented Apr 11, 2017 by bluegenel
Edit page q2apro-ajax-usersearch-page.php

change line 57

from this

WHERE `handlel` LIKE #

to this

WHERE `email` LIKE #
commented Apr 11, 2017 by bluegenel
edited Apr 11, 2017 by bluegenel
You probably don't want users being able to search email addresses so change this:
               
                // ajax return all user events
                $potentials = qa_db_read_all_assoc(
                    qa_db_query_sub(
                        'SELECT userid FROM ^users
                         WHERE `handle` LIKE #
                         LIMIT #',
                        '%'.$username.'%',
                        qa_opt('q2apro_ajax_usersearch_maxshow')                       
                    )
                );
               
to this

                // ajax return all user events
                if ( qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN ) {
                $potentials = qa_db_read_all_assoc(
                    qa_db_query_sub(
                        'SELECT userid FROM ^users
                         WHERE `email` LIKE #
                         LIMIT #',
                        '%'.$username.'%',
                        qa_opt('q2apro_ajax_usersearch_maxshow')                       
                    )
                );
                } else {
                $potentials = qa_db_read_all_assoc(
                    qa_db_query_sub(
                        'SELECT userid FROM ^users
                         WHERE `handle` LIKE #
                         LIMIT #',
                        '%'.$username.'%',
                        qa_opt('q2apro_ajax_usersearch_maxshow')                       
                    )
                );                   
                }

As admin you will then be able to search by email address. Simply sign out to search by username.
...