On this page
wp_ajax_add_user( string $action )
Ajax handler for adding a user.
Parameters
$actionstring Required-
Action to perform.
Source
File: wp-admin/includes/ajax-actions.php. View all references
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();
}
Related
Uses
| Uses | Description |
|---|---|
| WP_List_Table::single_row() wp-admin/includes/class-wp-list-table.php | Generates content for a single row of the table. |
| _get_list_table() wp-admin/includes/list-table.php | Fetches an instance of a WP_List_Table class. |
| edit_user() wp-admin/includes/user.php | Edit user settings based on contents of $_POST |
| WP_Ajax_Response::__construct() wp-includes/class-wp-ajax-response.php | Constructor – Passes args to WP_Ajax_Response::add(). |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| check_ajax_referer() wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. |
| get_userdata() wp-includes/pluggable.php | Retrieves user info by user ID. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_ajax_add_user