wp_ajax_add_user

Ajax handler for adding a user.

Description

wp_ajax_add_user( (string) $action ); 

Parameters (1)

0. $action (string)
Action to perform.

Usage

  1. if ( !function_exists( 'wp_ajax_add_user' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4. // Action to perform. 
  5. $action = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_ajax_add_user($action); 
  9.  

Defined (1)

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

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_add_user( $action ) { 
  2. if ( empty( $action ) ) { 
  3. $action = 'add-user'; 
  4.  
  5. check_ajax_referer( $action ); 
  6. if ( ! current_user_can('create_users') ) 
  7. wp_die( -1 ); 
  8. if ( ! $user_id = edit_user() ) { 
  9. wp_die( 0 ); 
  10. } elseif ( is_wp_error( $user_id ) ) { 
  11. $x = new WP_Ajax_Response( array( 
  12. 'what' => 'user',  
  13. 'id' => $user_id 
  14. ) ); 
  15. $x->send(); 
  16. $user_object = get_userdata( $user_id ); 
  17.  
  18. $wp_list_table = _get_list_table('WP_Users_List_Table'); 
  19.  
  20. $role = current( $user_object->roles ); 
  21.  
  22. $x = new WP_Ajax_Response( array( 
  23. 'what' => 'user',  
  24. 'id' => $user_id,  
  25. 'data' => $wp_list_table->single_row( $user_object, '', $role ),  
  26. 'supplemental' => array( 
  27. 'show-link' => sprintf( 
  28. /** translators: %s: the new user */ 
  29. __( 'User %s added' ),  
  30. '<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>' 
  31. ),  
  32. 'role' => $role,  
  33. ) ); 
  34. $x->send();