Skip to content

Commit

Permalink
query wp_users table to find user name suggestions for auto complete.
Browse files Browse the repository at this point in the history
both user login and display name column are queried.
  • Loading branch information
seanchen committed Feb 1, 2013
1 parent 3fd09b8 commit 4ae9fb2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
16 changes: 11 additions & 5 deletions wp-trac-client/ajax.php
@@ -1,24 +1,30 @@
<?php

/**
*
* wordpress AJAX callback for user anme suggestions.
*/
add_action('wp_ajax_nopriv_wptc_username_autocomplete', 'wptc_username_suggestion_cb');
add_action('wp_ajax_wptc_username_autocomplete', 'wptc_username_suggestion_cb');
function wptc_username_suggestion_cb() {

$searchTerm = $_POST['term'];
$searchTerm = $_REQUEST['term'];
// query wp_users table for the given term.
$users = array("abc", "cde");
$users = wptc_username_suggestion_query($searchTerm);

$suggestions = array();
foreach($users as $user) {
$suggestion = array();
$suggestion['label'] = 'Display Name - Email';
$suggestion['value'] = 'user_login';
// preparing label and value for each user.
// label: Display Name - Email
// value: user_login
$suggestion['label'] = $user->display_name . ' - ' .
$user->user_email;
$suggestion['value'] = $user->user_login;
$suggestions[] = $suggestion;
}

// we are using jQuery.getJSON to trigger AJAX request,
// it is different from direct AJAX call.
$response = $_GET["callback"] . "(" . json_encode($suggestions) . ")";
echo $response;
exit;
Expand Down
6 changes: 4 additions & 2 deletions wp-trac-client/js/trac-wikitoolbar.js
Expand Up @@ -134,9 +134,11 @@ jQuery(document).ready(function($) {
},
minLength: 2,
select: function(event, ui) {
// do nothing for now.
// selected value could get from ui param.
// ui.item.id, ui.item.value.
alert (ui.item.value);
// testing...
//alert (ui.item.value);
}
});

Expand All @@ -149,7 +151,7 @@ jQuery(document).ready(function($) {
select: function(event, ui) {
// selected value could get from ui param.
// ui.item.id, ui.item.value.
alert (ui.item.value);
//alert (ui.item.value);
}
});

Expand Down
23 changes: 23 additions & 0 deletions wp-trac-client/tags.php
Expand Up @@ -289,3 +289,26 @@ function wptc_create_ticket($summary, $description, $attrs) {
$attrs, True);
return $id;
}

/**
* preparing a list of user info based on the given
* search term.
*/
function wptc_username_suggestion_query($searchTerm) {

global $wpdb;
$likeTerm = '%' . $searchTerm . '%';
$query = $wpdb->prepare("
SELECT user_login, user_email, display_name
FROM wp_users
WHERE user_login like %s
OR display_name like %s
",
$likeTerm, $likeTerm
);

// using the default OBJECT as the output format.
$users = $wpdb->get_results($query);
return
apply_filters('wptc_username_suggestion_query', $users);
}
5 changes: 3 additions & 2 deletions wp-trac-client/templates/page-ticket-details.php
Expand Up @@ -67,9 +67,10 @@
if ($DEBUG) {
global $post, $current_blog;
// dump the change log
$ticket = wptc_get_ticket_actions($ticket_id);
//$ticket = wptc_get_ticket_actions($ticket_id);
$something = wptc_username_suggestion_query('se');
echo '<pre>';
var_dump($ticket);
var_dump($something);
echo '</pre>';

$parent_post = get_page($post->post_parent);
Expand Down

0 comments on commit 4ae9fb2

Please sign in to comment.