/**
 * Suggest user AJAX.
 *
 * @todo nonce
 * @todo auth
 */
function wpcf_access_wpcf_types_suggest_user_ajax()
{
    global $wpdb;
    $users = '';
    $q = '%' . wptoolset_esc_like(esc_sql(trim($_GET['q']))) . '%';
    $found = $wpdb->get_results($wpdb->prepare("SELECT ID, display_name, user_login \n\t\t\tFROM {$wpdb->users} \n\t\t\tWHERE user_nicename LIKE %s \n\t\t\tOR user_login LIKE %s \n\t\t\tOR display_name LIKE %s \n\t\t\tOR user_email LIKE %s \n\t\t\tLIMIT %d", $q, $q, $q, $q, 10));
    if (!empty($found)) {
        foreach ($found as $user) {
            $users .= '<li>' . $user->user_login . '</li>';
        }
    }
    echo $users;
    die;
}
示例#2
0
/**
 * Suggest user AJAX.
 */
function wpcf_access_wpcf_types_suggest_user_ajax()
{
    global $wpdb;
    $users = '';
    $q = wptoolset_esc_like(esc_sql(trim($_GET['q'])));
    $found = $wpdb->get_results("SELECT ID, display_name, user_login FROM {$wpdb->users} WHERE user_nicename LIKE '%%{$q}%%' OR user_login LIKE '%%{$q}%%' OR display_name LIKE '%%{$q}%%' OR user_email LIKE '%%{$q}%%' LIMIT 10");
    if (!empty($found)) {
        foreach ($found as $user) {
            $users .= '<li>' . $user->user_login . '</li>';
        }
    }
    echo $users;
    die;
}