wp_ajax_add_user() - WordPress 函数参考中文文档

返回介绍

wp_ajax_add_user()

发布于 2017-09-11 字数2353 浏览 852 评论 0

wp_ajax_add_user( string $action )

Ajax handler for adding a user.


描述


参数

$action

(string)
(Required)
Action to perform.


源代码

File: 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();
}

更新日志

Version 描述
3.1.0 Introduced.

相关函数

Uses

  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::single_row()
  • wp-admin/includes/list-table.php:
    _get_list_table()
  • wp-admin/includes/user.php:
    edit_user()
  • wp-includes/capabilities.php:
    current_user_can()
  • wp-includes/l10n.php:
    __()
  • wp-includes/pluggable.php:
    check_ajax_referer()
  • wp-includes/pluggable.php:
    get_userdata()
  • wp-includes/functions.php:
    wp_die()
  • wp-includes/class-wp-ajax-response.php:
    WP_Ajax_Response::__construct()
  • wp-includes/load.php:
    is_wp_error()
  • Show 5 more uses
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!