wp_ajax_add_user

The timeline below displays how wordpress function wp_ajax_add_user has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Handles adding a user via AJAX.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
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);
    }
    $user_id = edit_user();
    if (!$user_id) {
        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();
}

WordPress Version: 5.3

/**
 * Ajax handler for adding a user.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
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);
    }
    $user_id = edit_user();
    if (!$user_id) {
        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();
}

WordPress Version: 4.7

/**
 * Ajax handler for adding a user.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
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();
}

WordPress Version: 4.4

/**
 * Ajax handler for adding a user.
 *
 * @since 3.1.0
 *
 * @global WP_List_Table $wp_list_table
 *
 * @param string $action Action to perform.
 */
function wp_ajax_add_user($action)
{
    global $wp_list_table;
    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();
}

WordPress Version: 4.3

/**
 * Ajax handler for adding a user.
 *
 * @since 3.1.0
 *
 * @global WP_List_Table $wp_list_table
 *
 * @param string $action Action to perform.
 */
function wp_ajax_add_user($action)
{
    global $wp_list_table;
    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(__('User <a href="#%s">%s</a> added'), "user-{$user_id}", $user_object->user_login), 'role' => $role)));
    $x->send();
}

WordPress Version: 4.0

/**
 * Ajax handler for adding a user.
 *
 * @since 3.1.0
 *
 * @param string $action Action to perform.
 */
function wp_ajax_add_user($action)
{
    global $wp_list_table;
    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(__('User <a href="#%s">%s</a> added'), "user-{$user_id}", $user_object->user_login), 'role' => $role)));
    $x->send();
}

WordPress Version: 3.7

function wp_ajax_add_user($action)
{
    global $wp_list_table;
    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(__('User <a href="#%s">%s</a> added'), "user-{$user_id}", $user_object->user_login), 'role' => $role)));
    $x->send();
}