| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpdb; |
| 7 |
if (!($current_user->ID && $current_user->has_cap('wpsc_agent'))) {exit;} |
| 8 |
|
| 9 |
$term = isset($_REQUEST) && isset($_REQUEST['term']) ? sanitize_text_field($_REQUEST['term']) : ''; |
| 10 |
if (!$term) {exit;} |
| 11 |
|
| 12 |
$output = array(); |
| 13 |
|
| 14 |
$args = array ( |
| 15 |
'meta_query' => array( |
| 16 |
'relation' => 'OR', |
| 17 |
array( |
| 18 |
'key' => 'first_name', |
| 19 |
'value' => $term, |
| 20 |
'compare' => 'LIKE' |
| 21 |
), |
| 22 |
array( |
| 23 |
'key' => 'last_name', |
| 24 |
'value' => $term, |
| 25 |
'compare' => 'LIKE' |
| 26 |
) |
| 27 |
) |
| 28 |
); |
| 29 |
$wp_user_query = new WP_User_Query($args); |
| 30 |
$usermeta = $wp_user_query->get_results(); |
| 31 |
|
| 32 |
$users = get_users(array('search'=>'*'.$term.'*','number' => 5)); |
| 33 |
$users_dup = array_merge($users,$usermeta); |
| 34 |
$users = array_unique($users_dup, SORT_REGULAR); |
| 35 |
|
| 36 |
foreach ($users as $user) { |
| 37 |
$output[] = array( |
| 38 |
'id' => $user->ID, |
| 39 |
'label' => $user->display_name, |
| 40 |
'value' => $user->display_name, |
| 41 |
'email' => $user->user_email, |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
if (!$output) { |
| 46 |
$output[] = array( |
| 47 |
'id' => '', |
| 48 |
'label' => __('No matching users','supportcandy'), |
| 49 |
'value' => '', |
| 50 |
'email' => '', |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
wp_send_json($output); |
| 55 |
|