wp_ajax_add_user( string $action )
- Since
- 3.1.0
- Source
wp-admin/includes/ajax-actions.php:1741
Handles adding a user via AJAX.
Parameters
$actionstring- Action to perform.
Uses · 9
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- current_user_can()Returns whether the current user has the specified capability.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- edit_user()Edit user settings based on contents of $_POST
- is_wp_error()Checks whether the given variable is a WordPress Error.
- get_userdata()Retrieves user info by user ID.
- _get_list_table()Fetches an instance of a WP_List_Table class.
- __()Retrieves the translation of $text.
- WP_Ajax_Response::__construct()Constructor - Passes args to WP_Ajax_Response::add().
Source
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();}History
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-admin/includes/ajax-actions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.