Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Q2A Core by

I'm building the Mail Chimp plug-in and I'd like to give the admin an option of importing all existing confirmed members. I dug through the code and put this simple example together:

require_once QA_INCLUDE_DIR.'qa-db-users.php';
require_once QA_INCLUDE_DIR.'qa-db-selects.php';

$users=qa_db_select_with_pending(qa_db_top_users_selectspec(0, 100000000));

if (count($users)) {
  foreach ($users as $userid => $user)
    echo $user['email'] . '<br />';
} else
  echo qa_lang_html('main/no_active_users');

Is there something better than top_users to use for the selection of all members who confirmed their accounts?

1 Answer

+3 votes
edited by
you can just use a custom db_query:

            if(!QA_FINAL_EXTERNAL_USERS) {  // not WP-integrated
                $users = qa_db_query_sub('SELECT email FROM ^users WHERE flags&#', QA_USER_FLAGS_EMAIL_CONFIRMED);
                while ( ($email=qa_db_read_one_value($users,true)) !== null )
            else { // WP-integrated
                $users = qa_db_query_sub("SELECT user_email FROM wp_users WHERE user_activation_key=''");
                while ( ($email=qa_db_read_one_value($users,true)) !== null )
            function myImportFunction($email) {

                // import the email here.

Is there a common function to call for all cases or do I have to figure out if it's WP integrated or not? If that's the case, is there a way to figure out WP integration vs. not? and how would I get the email addresses in the case of WP integration?
if QA_FINAL_EXTERNAL_USERS is set, it is WP integrated.

In that case, you have to to a db query to select all users from the wp_users table, then run the query:

                $users = qa_db_query_sub('SELECT user_email FROM wp_users');
                while ( ($email=qa_db_read_one_value($users,true)) !== null )

(See the complete version edited above)
you might also want to add:

WHERE user_activation_key=''

to the wordpress query, I think that checks if they are verified or not.
Thanks. I just realized that for my current purposes, it'll be better for me to disable my plug-in if it's an external user and let the admin install a plug-in specifically designed for that platform.

If I need to grab all users in the future, I'll use SQL statement you provided.