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
if ( !function_exists( 'wp_ajax_add_user' ) ) { require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; } // Action to perform. $action = ''; // NOTICE! Understand what this does before running. $result = wp_ajax_add_user($action);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/ajax-actions.php
- function wp_ajax_add_user( $action ) {
- if ( empty( $action ) ) {
- $action = 'add-user';
- }
- check_ajax_referer( $action );
- if ( ! current_user_can('create_users') )
- wp_die( -1 );
- if ( ! $user_id = edit_user() ) {
- wp_die( 0 );
- } elseif ( is_wp_error( $user_id ) ) {
- $x = new WP_Ajax_Response( array(
- 'what' => 'user',
- 'id' => $user_id
- ) );
- $x->send();
- }
- $user_object = get_userdata( $user_id );
- $wp_list_table = _get_list_table('WP_Users_List_Table');
- $role = current( $user_object->roles );
- $x = new WP_Ajax_Response( array(
- 'what' => 'user',
- 'id' => $user_id,
- 'data' => $wp_list_table->single_row( $user_object, '', $role ),
- 'supplemental' => array(
- 'show-link' => sprintf(
- /** translators: %s: the new user */
- __( 'User %s added' ),
- '<a href="#user-' . $user_id . '">' . $user_object->user_login . '</a>'
- ),
- 'role' => $role,
- )
- ) );
- $x->send();
- }