Skip to content

Commit

Permalink
add the ajax action to vaidate username by querying wp_users table.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen committed Feb 4, 2013
1 parent 4ae9fb2 commit e44f60b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions wp-trac-client/ajax.php
Expand Up @@ -30,6 +30,32 @@ function wptc_username_suggestion_cb() {
exit;
}

/**
*
*/
add_action('wp_ajax_nopriv_wptc_valid_username', 'wptc_valid_username_cb');
add_action('wp_ajax_wptc_valid_username', 'wptc_valid_username_cb');
function wptc_valid_username_cb() {
$username = $_POST['username'];
$ret = array();
$ret['valid'] = True;
global $wpdb;
$query = $wpdb->prepare("
SELECT id
FROM wp_users
WHERE user_login = %s
", $username);
$userId = $wpdb->get_var($query);
if($userId === NULL) {
// username not exist.
$ret['valid'] = False;
$ret['username'] = $username;
}

echo json_encode($ret);
exit;
}

/**
* the ajax wrappers for the trac functions
* The _cb suffix stands for Call Back
Expand Down

0 comments on commit e44f60b

Please sign in to comment.