public static function get_clients_ajax()
 {
     check_ajax_referer('displet_get_clients_nonce');
     if (isset($_POST['action']) && $_POST['action'] == 'displet_get_clients_request') {
         $args = array('orderby' => 'display_name');
         if (current_user_can('manage_options')) {
             $clients = DispletRetsIdxLeadsModel::get_users(false, $args);
         } else {
             $user_id = get_current_user_id();
             if (!empty($user_id)) {
                 $clients = DispletRetsIdxLeadsModel::get_users($user_id, $args);
             }
         }
         if (!empty($clients) && is_array($clients)) {
             $output = array();
             foreach ($clients as $client) {
                 $output[] = array('name' => $client->display_name, 'id' => $client->ID);
             }
             echo json_encode($output);
         } else {
             echo 'No matching users.';
         }
     } else {
         echo 'There was an error processing your request. Please try again.';
     }
     die;
 }
 public static function upgrade_users_to_role_2()
 {
     $leads = DispletRetsIdxLeadsModel::get_users();
     if (!empty($leads)) {
         foreach ($leads as $lead) {
             $name = get_user_meta($lead->ID, 'nickname', true);
             $names = DispletRetsIdxUsersModel::get_first_and_last_name($name);
             if (!empty($names)) {
                 wp_update_user(array('ID' => $lead->ID, 'display_name' => $names['first_name']));
                 update_user_meta($lead->ID, 'first_name', $names['first_name']);
                 update_user_meta($lead->ID, 'last_name', $names['last_name']);
             }
             $api_user_id = get_user_meta($lead->ID, 'displet_api_user_id', true);
             if (empty($api_user_id)) {
                 $api_user_id = DispletRetsIdxUsersApiController::create_user($lead->user_email, $names['first_name'], $names['last_name']);
                 update_user_meta($lead->ID, 'displet_api_user_id', $api_user_id);
             }
             DispletRetsIdxSavedSearchesController::send_users_saved_searches_to_api($lead->ID, $api_user_id);
         }
     }
 }