edd_ajax_user_search

Search the users database via AJAX.

Description

edd_ajax_user_search(); 

Usage

  1. if ( !function_exists( 'edd_ajax_user_search' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-digital-downloads/includes/ajax-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = edd_ajax_user_search(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/ajax-functions.php  
  1. function edd_ajax_user_search() { 
  2. global $wpdb; 
  3.  
  4. $search = esc_sql( sanitize_text_field( $_GET['s'] ) ); 
  5. $results = array(); 
  6. $user_view_role = apply_filters( 'edd_view_users_role', 'view_shop_reports' ); 
  7.  
  8. if ( ! current_user_can( $user_view_role ) ) { 
  9. $results = array(); 
  10. } else { 
  11. $user_args = array( 
  12. 'search' => '*' . esc_attr( $search ) . '*',  
  13. 'number' => 50,  
  14. ); 
  15.  
  16. $users = get_users( $user_args ); 
  17.  
  18. if ( $users ) { 
  19.  
  20. foreach( $users as $user ) { 
  21.  
  22. $results[] = array( 
  23. 'id' => $user->ID,  
  24. 'name' => $user->display_name,  
  25. ); 
  26.  
  27. } else { 
  28.  
  29. $results[] = array( 
  30. 'id' => 0,  
  31. 'name' => __( 'No users found', 'easy-digital-downloads' ) 
  32. ); 
  33.  
  34.  
  35. echo json_encode( $results ); 
  36.  
  37. edd_die();